【问题标题】:How to set Firestore Rule searching for a reference如何设置 Firestore 规则搜索参考
【发布时间】:2021-08-23 07:56:00
【问题描述】:

我正在尝试根据用户的 uid 请求用户的 customerId,以便我可以使用该 customerId 来根据其他集合的非规范化结构在应用程序中进行未来读取/写入。

match /customers/{customerId} {
     allow read: if debug(/databases/$(database)/documents/users/$(request.auth.uid) in resource.data.users);
     // allow list: if request.auth.uid in resource.data.users;
     allow write: if false;
}
const userRef = firestore
                .collection("users")
                .doc("AKwPD9IUq8oyLYb454XaA7JUmpyO")
await firestore
  .collection("customers")
  .where("users", "array-contains", userRef).get()

Firebase 错误: 空值错误。对于“列表”@ L13,空值错误。对于“列表”@ L14

当我更改为read: truelist: true 时,允许查询(所以我知道这是正确的match,只是规则错误)

【问题讨论】:

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


    【解决方案1】:

    好生气——答案是https://stackoverflow.com/a/51115385/1166285

    Firebase 模拟器的版本与我项目的 firebase 软件包不同,因此 npm install -g firebase-tools 修复了它。

    浪费了大约 6 个小时 ?? 我希望在 Firebase 工作的人看到这个!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-01
      • 2018-08-12
      • 2011-05-02
      • 2019-09-15
      • 2019-11-03
      • 2019-08-29
      • 1970-01-01
      • 2019-10-06
      相关资源
      最近更新 更多