【问题标题】:Permissions with where clause on data field数据字段上带有 where 子句的权限
【发布时间】:2021-01-20 09:09:52
【问题描述】:

我希望用户能够读取和删除他们受邀创建记录的人在 Firebase 上创建的记录。

创建的记录有一个字段“resource.data.ownerUid”,其中 ownerId 是邀请其他人创建记录的用户的 uid。

如果我尝试类似:

allow read, delete: if request.auth.uid == resource.data.ownerUid;

但我在“获取”步骤中被拒绝:

firestore.collection('screeningResponses')
  .where('screeningId', '==', screeningId)
  .get()

结果

FirebaseError: Missing or insufficient permissions.

那时我正计划遍历 QuerySnapshot 并删除记录,但无法做到这一点。有什么建议吗?

【问题讨论】:

    标签: javascript google-cloud-firestore firebase-security


    【解决方案1】:

    Firebase 安全规则不会自行过滤数据。相反,他们只是根据规则检查是否允许读取操作。

    因此,您的查询必须复制规则要求的内容。由于您的规则要求用户是他们读取的数据的所有者,因此查询也必须这样做:

    firestore.collection('screeningResponses')
      .where('ownerUid', '==', firebase.auth().currentUser.uid) // ? this is new
      .where('screeningId', '==', screeningId)
      .get()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多