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

174
Vistas
How can i set auto redirect if cookie was set before in nextjs?

Halo, i'm very confuse with this condition.. i already set cookies if user was regist or login before.. but if i refresh the page.. the cookie was not read and not directed to page that i set before

my code is

import "bootstrap/dist/css/bootstrap.min.css";
import { useStore } from "../src/redux/store";
import { Provider } from "react-redux";
import { useEffect } from "react";
import { authService } from "../src/services/AuthServices";
import { useRouter } from "next/router";
import { SSRProvider } from "react-bootstrap";

function MyApp({ Component, pageProps }) {
  const store = useStore(pageProps.initialReduxState);
  const dataAuth = authService.isLogin();
  const router = useRouter();
  const routeList = ["/login"];
  useEffect(() => {
    if (!dataAuth) {
      router.push("/");
    }
  }, []);
  return (
    <SSRProvider>
      <Provider store={store}>
        <Component {...pageProps} />
      </Provider>
    </SSRProvider>
  );
}

export default MyApp;

does anyone can help ?

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

0

you should include dataAuth in the useEffect dependencies array, see the code below:

useEffect(() => {
    if (!dataAuth) {
      router.push("/");
    }
  }, [dataAuth]); <-it will make this effect run every time the dataAuth changes
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