Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

280
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda