【问题标题】:Using resource.data in Firestore rules在 Firestore 规则中使用 resource.data
【发布时间】:2018-06-05 02:37:19
【问题描述】:

我有以下 Firestore 规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
        allow read: if true;
    }
    match /institutions/{institution}/watches/{watch} {
      allow read, update, delete: if request.auth.email == resource.data.email;
      allow create: if request.auth.email != null;
    }
  }
}

基本上,我希望/institutions/{institution}/watches 下的任何文档都可以读取/更新/删除当且仅当文档上的电子邮件与用户的电子邮件相同时。但是,当我使用示例文档通过模拟器运行此操作时,我无法使访问控制工作,并且我还在 API 客户端上收到权限被拒绝错误。

有什么方法可以进一步调试/我的上述规则中缺少什么吗?

【问题讨论】:

  • 我认为 allow read: if true; 如果布尔值?不知道你能不能像if true那样做
  • @RonRoyston if true 在 Firestore 安全规则中正确使用。您可以查看the docs 了解更多信息:)

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


【解决方案1】:

我认为request.auth.email 应该是request.auth.token.email。见https://firebase.google.com/docs/reference/rules/rules.firestore.Request#auth

【讨论】:

    猜你喜欢
    • 2023-02-21
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    • 2019-09-20
    • 2020-04-16
    • 1970-01-01
    • 2019-05-07
    相关资源
    最近更新 更多