首页 > 解决方案 > 如果用户已登录并具有特定 UID,则仅加载页面的功能?

问题描述

现在我有一个带有 Firebase 的基本登录页面。但是,我想知道如果有人具有特定的 UID 并且他们已登录,我如何仅加载网页。

现在我有:

    <h3 style="color: white;">Welcome User</h3>
    <p id="user_para" style="color: white;">Welcome to Firebase web login Example. You're currently logged in.</p>
    <button onclick="logout()">Logout</button>
  </div>

但这有一个问题。它在客户端,这意味着任何人都可以看到其中的数据。这将是未来的一个问题,因为该网站将用于存储敏感数据。有谁知道如果该人已登录并具有特定 UID,我如何编写规则/函数以从页面中提取数据?

标签: javascriptfirebasefirebase-realtime-databasefirebase-authenticationfirebase-storage

解决方案


我就是这样做的,你应该有一些文件来检查数据库并以真/假响应..这是我的文件FileToCheckDataBase

function CheckUid(uid) {
      var xhttp;
         xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function () {
          if (this.readyState == 4 && this.status == 200) {
           //here is the answer from file after checking in db
           if(this.response==1){
           //user uid is ok
           //do something.. usually continue
           }
           else{
             //  kick him out
           }
          }
      };
      xhttp.open("GET", "FileToCheckDataBase?uid="+uid, true);
      xhttp.send();
  
  }

推荐阅读