[英]How to use Firestore Document Reference in Firebase Cloud Storage Security Rules?
allow write: if /databases/(default)/documents/users/$(request.auth.uid) in
firestore.get(/databases/(default)/documents/businesses/$(businessDocId)).data.team;
The get().data.team
value is an array which contains a Firestore document reference type. get().data.team
值是一个包含 Firestore 文档引用类型的数组。
I'm getting a permission error when using this for Cloud Storage, although a similar call in Firestore security rules works.将此用于 Cloud Storage 时出现权限错误,尽管 Firestore 安全规则中的类似调用有效。
That first line looks off.第一行看起来不对。
What do you expect this to do?你希望它做什么?
/databases/(default)/documents/users/$(request.auth.uid)
If you want to read a field from the document in Firestore, use firestore.get()
there too, just as you do in the second line:如果你想从 Firestore 中的文档中读取一个字段,也可以在那里使用
firestore.get()
,就像你在第二行中所做的那样:
allow write:
if firestore.get(/databases/(default)/documents/users/$(request.auth.uid)).data.fieldToCheck
in firestore.get(/databases/(default)/documents/businesses/$(businessDocId)).data.team;
Working solution:工作解决方案:
function isBusinessOwner(businessDocId) {
let businessTeamArray = firestore.get(/databases/(default)/documents/businesses/$(businessDocId)).data.team;
let businessOwner = businessTeamArray[0];
return businessOwner in businessTeamArray;
}
Unfortunately with this solution, I have to manually choose an index in the array, therefore restricting the possibility of having multiple business owners in the array to compare against.不幸的是,对于这个解决方案,我必须手动选择数组中的索引,因此限制了数组中有多个企业主进行比较的可能性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.