我将用户访问权限存储在我的帐户文档account / {accountId}
的对象数组中access: [
{uid:"xyz123",level:"admin"}
{uid:"xyz456",level:"view"}
]
我可以使用in运算符设置一个Firestore规则,以检查请求数据的用户ID是否与此访问数组中的对象之一匹配。
这在模拟器中有效,但是在实时应用中,我的权限被拒绝
match /accounts/{document=**} {
allow read: if {"level":"owner", "uid":request.auth.uid} in resource.data.access;
allow read: if {"level":"view", "uid":request.auth.uid} in resource.data.access;
allow read: if {"level":"edit", "uid":request.auth.uid} in resource.data.access;
allow read: if {"level":"restricted", "uid":request.auth.uid} in resource.data.access;
}
我想保留对文档的访问权限,因为它们需要基于文档。
答案 0 :(得分:0)
以上工作正常。我在安全规则中也缺少管理员级别的检查,而在我对数据库的调用中却发现该数组包含任何数组
[{"level":"owner", uid},{"level":"admin", uid},{"level":"view", uid},{"level":"edit", uid}]
这是规则
allow read: if {"level":"owner", "uid":request.auth.uid} in resource.data.access;
allow read: if {"level":"admin", "uid":request.auth.uid} in resource.data.access;
allow read: if {"level":"view", "uid":request.auth.uid} in resource.data.access;
allow read: if {"level":"edit", "uid":request.auth.uid} in resource.data.access;
allow read: if {"level":"restricted", "uid":request.auth.uid} in resource.data.access;
无论您在firestore请求中输入的内容如何,都必须受到安全规则的保护。