google-cloud-firestore - get() 不起作用,错误不遵循文档
问题描述
添加 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;
}
}
}
}
允许读取 if get(..line 是第 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}
对我来说,这些错误都没有任何意义,因为 match 在那里,以及我刚刚从文档中复制的所有其他内容......作为参考,这里是 Firebase 文档中的 get() 示例:
allow delete: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.admin == true
我错过了什么?
解决方案
推荐阅读
- accounting - BankEntryLine 的精确更改 GLAccount
- postgresql - Postgres DB Schema - 多列 vs 一个 json 列
- c# - 未找到实体类型。确保实体类型已添加到模型中
- string - 按后缀排序列表
- amazon-web-services - Docker 守护进程分配已被占用的临时端口
- laravel - Laravel 8 - 计算点击次数但用户不能向该功能发送垃圾邮件
- python - 在 Pytorch 中重写 TensorFlow 模型时出错
- css - 如何在不同的网格列中渲染数组中的元素 React
- wordpress - wp_nav_menu 中用于幻灯片的按钮
- swagger - OpenAPI 3:将对象数组用于 requestBody 示例