Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!