我想为不同的用户角色做出不同的许可 .
例如,当用户不是 super-owner 时,不要让他在我的项目表中写 .
这就是我试图做的事情:
{
"rules": {
"items": {
".write": "auth.authority == 'super-owner'"
}
}
}
但是我注意到 authority
字段存储在我自己创建的 users
节点中,并且被关联到Firebase auth
. 如何通过规则访问当前登录用户的 users->authority
?
更新:我试过这个:
".read": "root.child('users/'+auth.uid).authority.exists()",
但我得到 Error saving rules - Line 10: No such method/property 'authority'.
1 回答
您收到此错误,因为
root.child('users/'+auth.uid)
返回的DataSnapshot
实例当然没有authority
属性 . 但它有hasChild
方法 .有关
DataSnapshot
方法的完整列表,请访问以下链接 .https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot .
试试这个 .
或这个
或 shortest version