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

276
Vistas
How to delay page transition in NextJs

I am trying to protect my private pages using HOC withAuth. Protection works fine but i dont want users to see loading for second while access token is being retrieved from local storage. And if i were to just return null after redirecting i get error that says received div without enclosing div (or something like that). Is there any way to delay route transition ? My HOC is

export function withAuth<T extends TWithAuth = TWithAuth>(
   WrappedComponent: React.ComponentType<T>,
   ): React.ComponentType<T> {
const InnerComponent = (props: T) => {
    const [loading, setLoading] = useState(true);
    const router = useRouter();
    useEffect(() => {
        const accessToken = TokenService.getAccessToken();

        if (!accessToken) {
            router.replace('/auth/login');
        } else {
            setLoading(false);
        }
    }, []);
    return loading ? <div>loading</div> : <WrappedComponent {...props} />;
};

InnerComponent.displayName = `withAuth(${WrappedComponent.displayName || WrappedComponent.name}`;

return InnerComponent;

}

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

0

Maybe you can use getServerSideProps on your private pages and wrap it inside your component that's handling the logic and would return a

{ redirect: { destination: "/auth/login" } }

if there is no accessToken

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