Javascript firebase数据库安全规则:仅限制参与者的读写?
我的数据存储当前设置如下:Javascript firebase数据库安全规则:仅限制参与者的读写?,javascript,firebase,firebase-realtime-database,firebase-security,Javascript,Firebase,Firebase Realtime Database,Firebase Security,我的数据存储当前设置如下: "event": { "$eventID": { "participants": { "$uid1": true "$uid2" : true ... } ...Other event details objects... } }, "eventParticipants": { $uid: { $eventId1
"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 ",
},
},
好几天来我一直在为这个问题挠头。感谢您的帮助 来不及回答,但如果其他人遇到同样的问题,请分享 只有定义了父规则,子规则才是一致的 如果未定义父项,则默认情况下读写为false 在本例中,您定义的是写入规则,而不是.read的规则
这就是为什么您不能在子节点中读取数据。太晚了,无法回答,但如果其他人遇到同样的问题,请共享此信息 只有定义了父规则,子规则才是一致的 如果未定义父项,则默认情况下读写为false 在本例中,您定义的是写入规则,而不是.read的规则 这就是为什么不能在子节点中读取