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