在 Firebase 我有一个users
“节点”,看起来像:
users: {
someUid: {
username: 'someUsername'
activeConversations: {},
profile_picture: ''
... lots of other children
},
...
},
anotherNode: {
},
... hundreds of other nodes
我现在的规则:
{
"rules": {
".read": true,
".write": true,
"users": {
".indexOn": [
"username"
]
},
"friendRequests": {
".indexOn": [
"timeSent"
]
}
}
}
我想做的是限制孩子的访问users
“节点”仅适用于拥有子节点的客户端。例如,someUid
child 只能由具有 uid 的客户端写入someUid
。其他“节点”如anotherNode
任何登录的客户端都可以写入/读取。
此外,任何登录的客户端都应该能够写入profile_picture
and activeConversations
in the users
doc.
如何实现这一目标,而不必在每个节点上放置读/写规则?
谢谢
我认为@Bradley Mackey 已经接近了,但只需要一个小小的调整。
{
"rules": {
"users": {
".indexOn": ["username"],
// wildcard, matches any node under 'users'
"$someUid": {
"$other" : {
".read": "($other == 'profile_picture' || $other == 'activeConversations') || auth.uid == $someUid",
".write": "($other == 'profile_picture' || $other == 'activeConversations') || auth.uid == $someUid",
}
}
},
"$anythingelse": {
".read": "auth != null",
".write": "auth != null",
}
}
}
The ".validate":
field 确保字段匹配特定格式。如果该字段是 profile_picture 或 activeConversations,则此处的读取和写入应该为每个人提供读取和写入访问权限,并为用户提供对其他所有内容的访问权限。
EDIT:
我添加了另一条规则,该规则允许任何登录用户对任何非用户节点进行读写访问。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)