因此,尝试设置我的 firestore 数据库,并且我有一个名为 Users 的集合,用于存储用户信息。我还有每个用户的 Towers 子集。我的用户文档有一个用于安全设置的 playerUid 字段。这是我目前的安全规则:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if request.auth.uid != null;
}
match /users/{user=**}{
allow read, create: if request.auth.uid != null;
allow update: if request.auth.uid == resource.data.playerUid;
}
}
}
这允许用户阅读、创建他们的用户文档和塔文档的子集合,但他们不能编辑子集合。塔文件中没有 playerUid。有没有办法使用用户文档中的 playerUid 来验证更新塔的身份?或者我是否需要在塔文件中添加一个 playerUid 字段以进行身份验证
最佳答案
您可以 get
用户文档中的规则Towers
子集合,如 Firestore documentation on accessing other documents 中所示:
allow delete: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.admin == true
或者,如果用户在子集合的文档中,您确实可以包含 UID。这将防止需要在规则中读取额外的文档。
关于google-cloud-firestore - Firestore 的安全规则允许访问基于 UID 的所有子集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49419851/