I want to make my website be "locked" as long as someone is not logged in. The implemented login system uses Google Firebase so I have some easy and secure of letting the user log in.
Currently I coded an if statement that redirects you to the login page if you're not logged in. I know that it could be easily bypassed as the script is client-side so I wanted to ask what the best way would be for me to make this process more secure. I thought about using a script to insert the whole html into the page when the user is logged in but this also means that the whole html is going to be in a client-sided script which is no good.
auth.onAuthStateChanged(function(user) {
if (user) {
if(window.location.href =="login.html"){
mail = user.email;
window.alert("on login logged in. redirecting to index User Email: " + mail);
window.location.replace ("index.html");
}
} else {
window.alert(window.location.href);
if(window.location.href !="login.html"){
mail = null;
window.alert("not on login and logged out. Redirecting to login page Email: " + mail);
window.location.replace = "login.html";
}
}
});