【发布时间】:2020-06-10 14:43:47
【问题描述】:
您好,我在这里对 Firebase 用户 UID 和 Firestore 文档 ID (userId???) 感到有些困惑...并寻求帮助 :-)
通过创建用户,我得到一个 UID 并将其写入数据库
let db = Firestore.firestore()
db.collection("user").addDocument(data: [
"name": "confused",
"uid": result!.uid ])
通过这样做,我得到了一个唯一的文档 ID(标记为绿色),我认为它也是 userId:
我想要实现的是用户只能读写他的文档(绿色)而不能读写其他文档(红色)
因此我使用了以下规则
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Make sure the uid of the requesting user matches name of the user
// document. The wildcard expression {userId} makes the userId variable
// available in rules.
match /user/{userId} {
allow read, update, delete: if request.auth.uid == userId;
allow create: if request.auth.uid != null;
}
}
}
所以 UID 和文档 ID (userId???) 应该有联系吧?但我真的不明白?!在我的应用程序中,我想检索用户的文档 ID,以便稍后在 http-trigger 上使用它,但我只能获取 UID
print(Auth.auth().currentUser!.uid)
有什么想法还是我完全搞错了?
【问题讨论】:
标签: swift google-cloud-firestore firebase-security