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

272
Vistas
window.location.href infinite looping

im using firebase auth to allow users to signup and login to the website,so im using onAuthStateChanged to allow them access to other pages when logged in,and to have them stay on the login page if they are not logged in ,however i am running into an infinite loop with my window.location.href and i don't understand why at all this is my code

auth.onAuthStateChanged(user =>{
if(user){
  window.location.href = "/pages/home.html";
}else{
  
  window.location.href = "/";
}

});

the solution i tried was this:

auth.onAuthStateChanged(user =>{
if(user){
  if(window.location.href !== "/pages/home.html"){
  window.location.href = "/pages/home.html";
  }
}
if(!user){
  if(window.location.href !== "/"){
    window.location.href = "/";
  }
}
  

});

to try to avoid the infinite looping since it shouldn't go into the if more than once but it did not work at all,i also tried window.location.replace and i got the same result.. any help is appreciated thank you

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