我只希望用户能够在列表中包含该组的情况下加载该组,我将如何为此编写规则?
还是有一种方法可以编写规则以在firebase push数组中查找值?
例如,我想编写一条规则,使其看起来像这样。该规则无效,但旨在以此来解释我的观点。
"groups":{
"$group_id":{
".read":"root.child('users').child(auth.uid).child('groups').hasChildValue().val() == $group_id"
}
},
我只希望用户能够在列表中包含该组的情况下加载该组,我将如何为此编写规则?
更新,我如何修复它。-将数据重组为平坦的。摆脱使用push()添加值的麻烦。-平面数据使引用键变得容易。
"groups":{
// root/users/auth.uid/groups/$group_id
"$group_id":{
// only read if the user has the group_id
".read":"root.child('users').child(auth.uid).child('groups').child($group_id).exists()",
// only write if logged in and it's new || if the user has group id
".write":"(auth != null && !data.exists() && newData.exists()) || root.child('users').child(auth.uid).child('groups').child($group_id).exists()"
}
},
似乎您正在尝试“过滤”组数据,这不是Firebase规则的目的。请参阅参考链接:https :
//firebase.google.com/docs/database/security/securing-data#rules_are_not_filters
对于您想要实现的目标(限制对组的读取访问),您需要根据应用程序访问数据模型的方式来对其进行调整。让我知道这是否是您要寻找的内容,我可以更新我的答案。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句