Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
Loading a next-auth protected page shows the wrong message while and before loading

Consider a sinple next.js page like this

const Index: NextPage = () => {

    const {data: session} = useSession();
    const [data, setData] = useState(null);
    const [isLoading, setLoading] = useState(false);

    useEffect(() => {
            setLoading(true)
            fetch('/api/myEndpoint')
                .then((res) => res.json())
                .then((data) => {
                    setData(data);
                    setLoading(false);
                });
    }, []);

    if(isLoading) {
        return <Spinner/>;
    }

    if(session) {
        return <p>here is my protected content</p>
    } else {
        return <p>you cant see this page</p>
    }
}

When I am not logged in I see "you cant see this page", then the spinner, then again "you cant see this page". And that's fine.

But when I am logged in, I see "you cant see this page", then the spinner, and then the protected content.

Same thing even if I try

if(session && data) {

How can I get rid completly of the "you cant see this page" until the page is completly loaded?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try : if(session && !isLoading) or if(session && isLoading===false)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda