我的数据存储区目前设置如下:
"event": {
"$eventID": {
"participants": {
"$uid1": true
"$uid2" : true
...
}
...Other event details objects...
}
},
"eventParticipants": {
$uid: {
$eventId1,
$eventI2,
...
}
...more users
}
我希望这样只有在事件参与者列表中的用户才能读取或写入该级联,但我在使其正常工作时遇到一些麻烦。在firebase控制台中,我已经测试了这个规则并且它在测试控制台中运行,但除非我有一个全局读取,否则数据实际上不会显示:“auth!= null”
这是我尝试过的规则:
"event": {
".write": "auth != null",
"$eventID": {
".read": "root.child('eventParticipants').child(auth.uid).child($eventId).val() == true",
"participants": {
"$uid": {
},
},
},
},
"eventParticipants": {
".write": "auth != null",
"$uid":{
".read": "$uid === auth.uid ",
},
},
以下是我尝试过的规则:
"event": {
".write": "auth != null",
//".read": "auth != null",
"$eventID": {
".read": "root.child('eventParticipants').child(auth.uid).child($eventId).val() == true",
//".read": "root.child('eventParticipants/'+$uid+'/').val() === auth.uid",
// ".read": "data.parent().val() === auth.uid",
//".validate": "$uid.exists()"
"participants": {
// ".read": "data.child(auth.uid).exists()",
//".read": "data.child() == auth.uid",
"$uid": {
//".read": "root.child('eventParticipants/'+$uid+'/').val() === auth.uid",
// ".read": "data.parent().val() === auth.uid",
//".validate": "$uid.exists()"
},
},
},
},
"eventParticipants": {
".write": "auth != null",
//".read": "auth != null",
"$uid":{
".read": "$uid === auth.uid ",
},
},
这个问题让我头疼了好几天。任何帮助赞赏!
答案 0 :(得分:0)
回答为时已晚,但如果其他人遇到同样的问题,请分享此信息。
仅当定义了父规则时,子规则才一致。
如果未定义父母规则,则默认情况下读取和写入为 false。
在您的情况下,您定义的是写入规则,而不是 .read 的规则
这就是为什么你不能在子节点中读取。