angularjs – 需要检查数组中值的Firebase规则(安全规则中的contains())

前端之家收集整理的这篇文章主要介绍了angularjs – 需要检查数组中值的Firebase规则(安全规则中的contains())前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在firebase规则中检查数组中的值.我想做这样的事情:

root.child('connections/'+auth.uid).child('friends').child(someFriendId).exists()

因此,在当前用户的连接节点下,如果在friends数组中存在someFriendId,则允许访问. ‘someFriendId’不是friends数组的键,也就是使用firebase push()方法生成自动ID.

解决方法

一般来说,avoid arrays in distributed data,并在结构数据指南中阅读 Arrays in Firebase.

您无法在Firebase安全规则中执行“包含”.相反,您需要将用户存储为密钥,类似于we demonstrate this use case in the security docs.

因此,给出您的示例,唯一的更改是使用用户ID替换数组索引,并将值更改为布尔值(或任何其他有用的值).然后您的安全规则可以构造为:

root.child('connections/'+auth.uid+'/friends/'+someFriendId).exists();

猜你在找的Angularjs相关文章