google-cloud-firestore - Firestore 的安全规则允许访问基于 UID 的所有子集合

标签 google-cloud-firestore firebase-security

因此,尝试设置我的 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/

相关文章:

javascript - Firestore 长获取请求

firebase - Flutter Firestore 缓存

javascript - Firebase 规则 : Problem with role based authentication in groups and . 其中()

firebase - FieldValue.increment 的 Firestore 安全规则

android - 有没有一种方法可以设置和合并而无需仅为 1 个值创建映射

ios - 如何从 Firestore 将包含对象的数组获取到 Xcode 中的模型

firebase - 验证 newData 是否为具有 firebase 数据库规则的数组

如果文档 ID 包含字符串,则 Firebase Firestore 安全规则允许

javascript - 验证 id 是否存在在 Firebase 中被忽略

node.js - Firestore 安全规则 : How to enforce the number of fields CREATED in a Firestore document thru security rules?