【问题标题】:How to set Firestore security rules where an array contains a specific value如何在数组包含特定值的情况下设置 Firestore 安全规则
【发布时间】:2020-12-01 08:27:10
【问题描述】:

我想设置这样的规则:当用户的uid包含在城市文档的数组字段中时,该用户具有权限。

我是这样弄的。请告诉我该怎么做

allow read : if (city.some-array.contain(uid));

service cloud.firestore {
  match /databases/{database}/documents {

    // Match any document in the 'cities' collection
    match /cities/{city} {
      allow read: ***if <condition>;***
      allow write: if <condition>;
    }
  }
}

【问题讨论】:

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


【解决方案1】:

您可以使用resource.data,一个包含操作前当前数据的对象,结合in来实现。

match /cities/{city} {
    allow read, write: if request.auth.uid in resource.data.authorizedUsers
    // replace authorizedUsers with the name of your array field
}

【讨论】:

    猜你喜欢
    • 2021-04-08
    • 2020-12-28
    • 2019-11-25
    • 2019-06-02
    • 1970-01-01
    • 2019-09-20
    • 2019-09-15
    • 2019-03-03
    • 2020-11-07
    相关资源
    最近更新 更多