需要检查数组中值的 Firebase 规则(安全规则中包含())
Firebase rule that needs to check for value in array (contains() in security rules)
如何在 Firebase 规则中检查数组中的值。我正在尝试做这样的事情:
root.child('connections/'+auth.uid).child('friends').child(someFriendId).exists()
所以在当前用户的connections节点下,如果friends数组中存在someFriendId,则允许访问。 'someFriendId' 不是 friends 数组的键,它是使用 firebase push() 方法自动生成的 ID。
一般来说,avoid arrays in distributed data, and read up on Arrays in Firebase 在结构化数据指南中。
您不能在 Firebase 安全规则中执行 "contains"。相反,您需要将用户存储为键,类似于 we demonstrate this use case in the security docs.
因此,根据您的示例,唯一的更改是用用户 ID 替换数组索引,并将值更改为布尔值(或任何其他有用的值)。那么您的安全规则可以构造为:
root.child('connections/'+auth.uid+'/friends/'+someFriendId).exists();
如何在 Firebase 规则中检查数组中的值。我正在尝试做这样的事情:
root.child('connections/'+auth.uid).child('friends').child(someFriendId).exists()
所以在当前用户的connections节点下,如果friends数组中存在someFriendId,则允许访问。 'someFriendId' 不是 friends 数组的键,它是使用 firebase push() 方法自动生成的 ID。
一般来说,avoid arrays in distributed data, and read up on Arrays in Firebase 在结构化数据指南中。
您不能在 Firebase 安全规则中执行 "contains"。相反,您需要将用户存储为键,类似于 we demonstrate this use case in the security docs.
因此,根据您的示例,唯一的更改是用用户 ID 替换数组索引,并将值更改为布尔值(或任何其他有用的值)。那么您的安全规则可以构造为:
root.child('connections/'+auth.uid+'/friends/'+someFriendId).exists();