这种保护我的网站的方式是否足够安全?我怎样才能使我的站点的保护成为服务器端的?

Is this way of protecting my website secure enough? How could I make the protection of my site be server-sided?

我想让我的网站 "locked" 只要有人没有登录。实施的登录系统使用 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";

    }
  }
});

如果您的网站托管在 Firebase 托管上,则所有文件都是 public。无法阻止用户访问特定文件。参见 Firebase Hosting - password protect website? and Can Firebase hosting restrict access to resources?

也就是说,秘密信息通常不直接在您的 HTML 中,而是在您从服务器加载的其他资源中,例如从数据库中加载。如果您使用的数据库来自 Firebase(Cloud Firestore,或实时数据库),您可以通过在您自己的 back-end 代码中使用 Firebase's server-side security rules. If you're using another database, or your own backend to serve the data that needs to be protected, look into verifying ID tokens 来确保只有授权用户才能访问数据,以确保用户有权访问数据。