I am having a lot trouble redirecting a user from the login page to the homepage after they successfully login (with the right email and password that they created. My website is written in HTML, CSS and Javascript, and I am using firebase for authentication. I have checked everywhere but can't seem to find a solution that works. I tried the method below (the last function is my attempt at redirection) and it seemed to work, however, it causes an infinite page refresh/reload. Can someone please help me out?
function signUp() {
var email = document.getElementById("email");
var password = document.getElementById("password");
const promise = auth.createUserWithEmailAndPassword(email.value, password.value);
promise.catch(e => alert(e.message));
alert("Registered");
}
function signIn() {
var email = document.getElementById("email");
var password = document.getElementById("password");
const promise = auth.signInWithEmailAndPassword(email.value, password.value);
promise.catch(e => alert(e.message));
alert("Logged in " + email.value);
}
function signOut() {
auth.signOut();
alert("Logged out");
}
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
var email = user.email;
alert("Active user: " + email);
window.location.href = "/Users/Me/Desktop/Website HTML/home.html";
}
else {
alert("No active user");
window.location.href = "/Users/Me/Desktop/Website HTML/login.html";
}
})