我正在使用firebase,我的用户设置如下:
{ "firebase-account-123": { "users": { "simplelogin:1": { "properties"{ "name": "john doe","email": "user@email.com" } "children": { "simplelogin:2":{ "name": "user 2","email": "user2@email.com" },} },"simplelogin:2": { "properties"{ "name": "user 2","email": "user2@email.com","disabled": false } } } }
我有“孩子”,帐户经理应该有权访问.我是新手,我正在尝试解决我遇到的一些权限问题.
我的规则目前只允许用户读/写自己的数据.
“.read”:“auth.uid == $userid”,“.write”:“auth.uid == $userid”
解决方法
如果要允许子桶下列出的用户ID也读取和写入数据,请尝试在安全规则中使用hasChild()方法.
例如,使用您在上面概述的相同数据结构:
{ "rules": { ".read": false,".write": false,"users": { "$userid": { ".read": "auth.uid == $userid",".write": "auth.uid == $userid","properties": { ".read": "root.child('users').child(auth.uid).child('children').hasChild($userid)" } } } } }