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

240
Vistas
How can I redirect a user to a certain page in my Next.js _app.tsx in a useEffect. Currently in infinite redirect loop

I am using Next.js and Firebase.

I want to allow users to sign up with Google, but I need to check at the app level whether the users status is "incomplete" or "active".

Here is my useEffect. I listen to userData here and if the status is "incomplete", I redirect the user to the place where I can finish their sign up process (e.g. ask for username).

useEffect(() => {
    if (currentUser && currentUser !== "unauthenticated") {
      const docRef = doc(db, "users", currentUser.uid);
      return onSnapshot(docRef, async (doc) => {
        let data = doc.data() as UserData;
        if (!data) {
          return;
        }
        if (data?.status === "incomplete") {
          router.push("/complete-user-data");
          return;
        }
        setData(doc.data() as UserData);
      });
    }
  }, [currentUser, router, setData]);

This would work however as the useEffect is constantly rerendering due to the router.push("/complete-user-data");, I am in a infinite loop.

Whats the best way of creating a top level listener that will basically block the user based on a certain condition and push them to a certain route?

Is there a way to only push to a route if the user isn't currently on that route (in my case, if they're not on /complete-user-data?)

about 4 years ago · Juan Pablo Isaza
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