javascript - 如果用户已登录并具有特定 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,我如何编写规则/函数以从页面中提取数据?
解决方案
我就是这样做的,你应该有一些文件来检查数据库并以真/假响应..这是我的文件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();
}
推荐阅读
- database - Oracle 数据库返回日期为 1951 而不是 2051
- python - 在Python中使用循环根据字符串值修改新列中的行值
- mysql - MYSQL 选择不适用于以前的版本
- r - 删除列的数字(零)并在数据框中创建一个新列
- python - ModuleNotFoundError:没有名为“fcntl”的模块
- javascript - 无法读取未定义的属性“onRowClickHandler”
- firefox - Firefox:关闭所有标签并*最后激活*
- reactjs - 访问css模块相关的问题
- javascript - JavaScript ES6 - 如何在类之间传递 API URLSearchParams
- vue.js - Vue 的 nextTick 之后如何拍摄 Storybook 的 Storyshots?