【发布时间】:2019-03-05 00:30:18
【问题描述】:
我面临两个问题:
- 您不能更改句点 '.'当您使用“request.auth.token.email”之类的内容时,“firebase 规则”中的字符(操作字符串和加入的选项非常有限,不支持替换函数)
- 如果使用 hashmap,您不能在查询中使用电子邮件,因为与“键”相同的句点字符。
由于上述问题而放弃 HashMap 方法,我正在尝试探索数组。有没有办法通过 request.auth.token.email 获取登录用户的电子邮件并将其与文档中数组的“电子邮件”元素进行比较?
例如 - 我有“bb@gmail.com”作为登录用户,我想获取“sharedWith”数组包含“bb@gmail.com”作为条目的所有文档并忽略其余部分文件。我可以在代码中实现它,但我想将此安排设置为“安全规则”,以使阅读文档更加健壮。
---------更新----------- 我尝试了拆分并加入我的安全规则,如下所示: (参考:Using the replace function in firestore security rules)
allow read: if isSignedIn() && resource.data.sharedWith[(request.auth.token.email).split('.').join(',')] in ["true"];
我的查询如下:
db.collection("Sites")
.whereEqualTo("sharedWith.bb@gmail,com","true")
我的文档有以下内容:
sharedWith
mm@gmail,com : "true"
bb@gmail,com : "true"
并且用户以“bb@gmail.com”身份登录
上述设置不起作用。我收到权限被拒绝错误。 我不知道我做错了什么,请帮忙。
【问题讨论】:
标签: firebase google-cloud-firestore firebase-security