Halo, estoy muy confundido con esta condición... ya configuré cookies si el usuario se registró o inició sesión antes... pero si actualizo la página... la cookie no se leyó y no se dirigió a la página que configuré antes
mi codigo es
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;¿alguien puede ayudar?
debe incluir dataAuth en la matriz de dependencias useEffect , vea el código a continuación:
useEffect(() => { if (!dataAuth) { router.push("/"); } }, [dataAuth]); <-it will make this effect run every time the dataAuth changes