【发布时间】:2019-11-01 04:57:43
【问题描述】:
只要有人没有登录,我想让我的网站被“锁定”。实现的登录系统使用 Google Firebase,所以我可以让用户登录变得简单而安全。
目前我编写了一个 if 语句,如果你没有登录,它会将你重定向到登录页面。我知道它很容易被绕过,因为脚本是客户端,所以我想问一下最好的方法是什么让我让这个过程更安全。我考虑过在用户登录时使用脚本将整个 html 插入页面,但这也意味着整个 html 将位于客户端脚本中,这是不好的。
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";
}
}
});
【问题讨论】:
标签: javascript login firebase-authentication