Firebase数据库规则:父级和子级的不同规则
我的数据库如下所示: user123是一个管理员。因此,他应该能够遍历条目中的所有节点。其他人无法看到项的子项,除非entryID的uid是auth.uidFirebase数据库规则:父级和子级的不同规则,firebase,firebase-realtime-database,firebase-security,Firebase,Firebase Realtime Database,Firebase Security,我的数据库如下所示: user123是一个管理员。因此,他应该能够遍历条目中的所有节点。其他人无法看到项的子项,除非entryID的uid是auth.uid 我该如何制定规则?若并没有可能的方法,任何关于更改数据库的建议:)若你们已经知道admin是,在你们的问题中是user123。那么您的数据库规则应该是 "entities": { "$entryId":{ // you don't what others to see other to see teh data
我该如何制定规则?若并没有可能的方法,任何关于更改数据库的建议:)若你们已经知道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"
}
}
你可以从这里获得更多信息
或者,您可以将条目模型更改为用户特定的
{
"entities" :{
"user465": {
"entry456": {
"text" : "Some sample text"
}
}
}
}
在这种情况下,您可以编写自己的规则
"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"
}
}
如果你已经知道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"
}
}
你可以从这里获得更多信息
或者,您可以将条目模型更改为用户特定的
{
"entities" :{
"user465": {
"entry456": {
"text" : "Some sample text"
}
}
}
}
在这种情况下,您可以编写自己的规则
"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”@namer。如果看到更新的答案,您也可以更改条目模型。但是管理员无法循环遍历所有条目,它显示“权限被拒绝”错误。@npk您可以添加一个额外的规则;如果一条规则被拒绝,则将检查以下规则。该规则是动态的。使用此规则,创建条目的用户无法读取该条目。例如,“user123”应该能够读取“entry456”@namer。如果看到更新的答案,您也可以更改条目模型。但是管理员无法循环遍历所有条目,它显示“权限被拒绝”错误。@npk您可以添加一个额外的规则;如果一条规则拒绝,则将检查以下规则。