Firestore安全规则:如何匹配公司参考字段ID?

时间:2019-12-25 17:44:02

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

我在Firestore上有两个集合:“用户”和“ companyInfos”。 我想创建一个Firestore安全规则,该规则仅在登录用户文档的公司引用字段的ID等于companyInfos的文档ID时才允许读取“ companyInfos”集合。

如果我在Firestore模拟器上测试,则不允许我获取请求。

无效的Firestore规则:

match /companyInfos/{documentId} {
  allow read: if request.auth.uid != null
  && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.company == documentId;
  allow write: if false;
}

Firestore屏幕截图:

Firestore模拟器:

Click to see screenshot

0 个答案:

没有答案