因此,您只希望 id 在Allowed 节点中的用户读取其他用户信息。对吧?
如果是这样......这是它的规则。
"Users": {
"$uid": {
".read": "root.child('Users/Allowed/'+auth.uid).exists()"
}
}
[更新]
$uid 是 $ 变量的示例(您可以给它起不同的名称,但它必须以 $ 开头)动态获取 Users 位置下的键值。
例如:我给你的规则只允许Allowed节点下的用户读取其他用户信息,但是如果这个用户不在,它会阻止用户读取自己的信息Allowed 节点。
如果你也想添加这个,你需要像这样改变你的规则。
"Users": {
"$uid": {
".read": "$uid == auth.id || root.child('Users/Allowed/'+auth.uid).exists()"
}
}
================================================ ===========================
在firebase规则中有predefined variables,例如now、root、auth、data、newData和$ variables。
当您的规则结构中有 $location 时,您可以使用
在规则表达式中匹配 $ 变量以获取
正在阅读或书写的实际孩子。所以假设我们想给每个
用户对自己的 /users/ 位置的读写权限。我们
可以使用:
复制自 firebase 文档https://firebase.google.com/docs/reference/security/database/#location
如果您想了解有关 Firebase 安全规则的更多信息,请阅读以下部分。
https://firebase.google.com/docs/database/security/
附言
你的结构不太好。 Users 节点下的数据混乱。您不应将Allowed 节点与 userIds 处于同一级别。相反,如果您在 Users 节点级别创建新节点 (allowedUsers) 并将 Allowed 数据移动到那里会更好。
AllowedUsers
- userid2
- userid3
Users
- userid1
- userid2
- userid3
- userid4