Firestore权限 [英] Firestore permissions
问题描述
如何配置权限,以便用户只能在拥有所有者的位置读写文件? 我的文档有一个称为所有者的顶级属性.
How do I configure permissions so that a user can only read and write documents where they are the owner? my documents have a top level attribute called owner.
我阅读了这些文档
https://firebase.google.com/docs/firestore/security/secure-data?authuser = 0#the_resource_variable
I read these docs
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
}
}
}
但是,这似乎不起作用.我不断收到权限不足错误. 我需要更改什么?
however this doesn't seem to work. i continuously get insufficient permission error. What do i need to change?
更新:
阅读了@Doug Stevenson链接的文档后,我决定选择
After reading the docs @Doug Stevenson linked I decided to go with
service cloud.firestore {
match /databases/{database}/documents {
match /analysis/{analysis} {
allow read, write: if request.auth.uid == resource.data.owner_uid;
}
}
}
所以我的初衷是当我们执行列表操作时:
So my original intent was that when we do a list operation:
a..仅返回属于用户的那些文档
b..该用户只能读取或写入该用户拥有的文档.
a. only those documents belonging to a user are returned
b. only documents a user owns can be read or written by that user.
使用以上配置 b..
我该如何完成 a.?
With the above configuration b. is accomplished.
how do I do accomplish a. ?
推荐答案
According to the documentation, you should use request.auth.token.email
(not request.auth.email
).
这篇关于Firestore权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!