【发布时间】:2017-11-24 11:20:29
【问题描述】:
如何配置权限以使用户只能在其所有者所在的位置读取和写入文档? 我的文档有一个名为 owner 的顶级属性。
我阅读了这些文档
https://firebase.google.com/docs/firestore/security/secure-data?authuser=0#the_resource_variable
看来这应该可行?
service cloud.firestore {
match /databases/{database}/documents {
match /analysis/{analysis} {
allow read, write: if request.auth.email == resource.data.owner
}
}
}
但这似乎不起作用。我不断收到权限不足错误。 我需要改变什么?
更新:
阅读@Doug Stevenson 链接的文档后,我决定选择
service cloud.firestore {
match /databases/{database}/documents {
match /analysis/{analysis} {
allow read, write: if request.auth.uid == resource.data.owner_uid;
}
}
}
所以我的初衷是,当我们进行列表操作时:
a. 仅返回属于用户的文档
b. 只有用户拥有的文档才能被该用户读取或写入。
通过以上配置b.就完成了。
我该如何完成a.?
【问题讨论】:
标签: firebase firebase-authentication firebase-security google-cloud-firestore