我正在努力理解一些 Firestore 安全概念。我想根据以下内容制定一条规则request.path
财产。
我的规则是这样的:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.path[0]=='appUsers';
}
}
}
...然后我用AngularFire2 https://github.com/angular/angularfire2添加这样的文档...
this.myAngularFirestore.doc('/appUsers/'+this.auth.auth.currentUser.uid).set({name: this.auth.auth.currentUser.displayName})
.then(()=>console.log('Added user'))
.catch(err=>console.log('Could not add user:', err.message));
我认为这应该很简单基于文档 https://firebase.google.com/docs/firestore/reference/security/?authuser=0#properties但我得到的只是错误 -Missing or insufficient permissions
.
我知道我已正确登录,并且我知道如果我打开安全性,查询会起作用allow read,write: if true;
那么我没有到达这里什么呢?
不应该request.path[0]
评估字符串appUsers
这里允许写入数据吗?
任何想法都感激地接受,因为到目前为止,我觉得这些规则在一起并没有多大乐趣。
欢呼所有
我建议使用内置路径匹配器版本:
service cloud.firestore {
match /databases/{database}/documents {
match /appUsers {
allow read, write;
}
}
}
或者,如果您确实想在条件中指定:
service cloud.firestore {
match /databases/{database}/documents {
match /{pathSegment} {
allow read, write: if pathSegment == "appUsers";
}
}
}
request.path
是完整路径(例如/projects/<projectId>/databases/(default)/documents/appUsers
,这意味着你实际上想要request.path[5]
(这就是为什么我们提供更简单、更易读的方法来做到这一点)。
编辑(2018 年 4 月 2 日):request.path
两者都支持List
and Map
使用权:
-
List
: request.path[5] == "appUsers"
-
Map
: request.path['pathSegment'] == "appUsers"
,但请注意,它仅适用于通配符(例如{name}
) values
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)