【发布时间】:2020-05-02 11:01:09
【问题描述】:
这是我在 Firebase 中的安全规则和条件
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /Product/{document=**} {
allow read: if true;
allow write: if request.auth.uid != null;
}
}
}
根据 Firestore 文档,我们可以在 once by this method 检索数据。
db.collection("Product").get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log(doc.id, " => ", doc.data());
});
});
如何从 Firebase 检索受保护的数据。如果它有一个有效的 uid,它会返回给你数据。在每个请求上发送我的用户状态或 uid 的正确方法是什么
【问题讨论】:
-
你的意思是你只想发送数据他自己的数据?如果 UID 是 1234,那么他只能访问名为 1234 的文档。像这样??
-
没有。任何注册的用户都可以访问数据
-
任何注册用户都可以读取数据。好的,谁可以写入或修改数据?
-
为简单起见,我只需要注册用户可以读写
-
你只需要在规则中添加这个:
allow read, write: if request.auth.uid != null;... 现在只有注册用户可以读/写。
标签: javascript google-cloud-firestore firebase-security