0
我有我的数据库是这样的:火力地堡的数据库规则:不同的规则对父母和孩子
user123是管理员。因此,他应该能够遍历条目中的所有节点。别人看不到项子除非ENTRYID的UID是auth.uid
我怎能设置此规则?如果没有可能的办法,任何建议改变dataBase :)
我有我的数据库是这样的:火力地堡的数据库规则:不同的规则对父母和孩子
user123是管理员。因此,他应该能够遍历条目中的所有节点。别人看不到项子除非ENTRYID的UID是auth.uid
我怎能设置此规则?如果没有可能的办法,任何建议改变dataBase :)
如果你已经知道admin是,在你的问题user123。然后,你的数据库规则应该像
"entities": {
"$entryId":{
// you don't what others to see other to see teh data
".read": "auth.uid == 'user123'"
// any one who is logged in should write to the /entries node
".write": "auth.uid != null"
}
}
如果你什么使规则更加动态的,那么你可以做
"entities": {
"$entityId":{
// you don't what others to see other to see teh data
".read": "root.child('users').child(auth.uid).child('isAdmin').val() == true || root.child('entities').child($entityId).child('uid').val() == auth.uid"
// any one who is logged in should write to the /entries node
".write": "auth.uid != null"
}
}
你可以从这里https://firebase.google.com/docs/reference/security/database/
或者获取更多信息,您可以将您的输入模型更改为用户特定的
{
"entities" :{
"user465": {
"entry456": {
"text" : "Some sample text"
}
}
}
}
In这种情况下,你写规则
"entities": {
"$userId":{
// you don't what others to see other to see teh data
".read": "root.child('users').child(auth.uid).child('isAdmin').val() == true || $userId == auth.uid"
// any one who is logged in should write to the /entries node
".write": "auth.uid == $userId"
}
}
规则是动态的。通过此规则,输入条目的用户无法阅读。例如,'user123'应该能够读取'entry456' – npk
@Nameer查看更新的答案,您也可以更改您的条目模型。 – bash
但管理员无法遍历所有条目,它显示'权限被拒绝'错误。 – npk