我正在尝试扩展一个social android aap,目前它的规则是公开的,它的数据结构是这样的,
{
"posts" : {
"postId1" : {
"authorId" : "abcd",
},
"postId2" : {
"authorId" : "abcd",
},
"postId3" : {
"authorId2" : "wxyz",
},
"postId4" : {
"authorId2" : "wxyz",
}
}
}我想要允许一个经过身份验证的用户在“post”节点中创建和删除他自己的帖子我试过了,
{
"rules": {
".read":"auth.uid != null",
".write":false,
"questions": {
"$uid": {
".write": "$uid === auth.uid"
}
}
}}但是这不允许用户创建帖子虽然用户可以在“帖子”节点中编辑或删除其先前存在的帖子,但是在“帖子”节点中似乎没有写权限。但是如果我允许“post”的写权限,那么由于级联规则,每个经过身份验证的用户都可以访问其他用户的数据。如何实现我想要的功能?
发布于 2018-04-29 19:37:44
首先,实时数据库规则的编写请参考firebase-bolt:https://github.com/firebase/bolt
这个工具使得编写规则变得很容易。
对于你的规则,这里有一个示例,它只允许作者更新帖子:
{
"rules": {
".read": "auth.uid != null",
"posts": {
"$postId": {
".write": "data.val() == null && newData.child('uid').val() == auth.uid || data.val() != null && newData.val() != null && data.child('uid').val() == auth.uid || data.val() != null && newData.val() == null && newData.child('uid').val() == auth.uid"
},
".read": "auth.uid != null"
}
}
}火基螺栓的等价物如下:
path / {
read() {auth.uid != null}
}
path /posts {
read() {auth.uid != null}
/{postId}{
create() { this.uid == auth.uid}
delete() { this.uid == auth.uid}
update() { prior(this.uid) == auth.uid}
}
}https://stackoverflow.com/questions/50085789
复制相似问题