get()不起作用,错误不遵循文档

时间:2019-07-14 11:35:38

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

添加Firestore规则以确保用户只能访问其公司的数据。 company是用户集合中其记录中的一个字段。集合的名称与公司相同。

根据Firestore文档,我认为这是应该起作用的方式。我确实尝试了一些对我来说更有意义的事情,例如添加括号,去除斜线,错误消息说是错误的,但是得到了相同的结果。

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
    allow read, write: if false;
    }

    match /{collectionName}/{document=**} {
      allow read: if get(databases/$(database)/documents/users/$(request.auth.uid)).data.company == collectionName;
      }

  }
}
      }

如果get(....行是第22行,则允许读取。 这是我尝试发布规则集时收到的错误消息。

 Line 22: Unexpected '$'.; Line 22: Missing 'match' keyword before path.; 
Line 22: Forward slash '/' found where identifier or binding expected.; 
Line 22: mismatched input '$' expecting {'{', '/', PATH_SEGMENT}; 
Line 22: Missing 'match' keyword before path.; 
Line 22: Forward slash '/' found where identifier or binding expected.; 
Line 22: mismatched input '$' expecting {'{', '/', PATH_SEGMENT}

对我来说,这些错误都没有道理,因为存在匹配项,而我刚刚从文档中复制的所有其他内容... 供参考,这是Firebase文档中的get()示例:

allow delete: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.admin == true

我想念什么?

0 个答案:

没有答案