[英]Firebase write permission denied
I can't figure out why firebase won't let me do this specific write. 我无法弄清楚为什么firebase不会让我做这个特定的写。 I feel like I do it the same in the simulator and it works there.
我觉得我在模拟器中也是这样做的,它可以在那里工作。 Below are my security rules for this section.
以下是本节的安全规则。
"joinRequests" : {
"$clanid": {
"$requesterid" : {
".read" : "$requesterid === auth.uid || root.child('clans/' + $clanid + '/members/' + auth.uid + '/admin').val() === true",
".validate": "newData.hasChildren(['request'])",
"request" : {
".write" : "true",
".validate": "newData.hasChildren(['name', 'message'])",
"name" : {
".validate": "newData.isString()"
},
"message" : {
".validate": "newData.isString()"
},
"$other": {
".validate": false
}
},
"approved" : {
".write" : "root.child('clans/' + $clanid + '/members/' + auth.uid + '/admin').val() === true || ($requesterid === auth.uid && !newData.exists())",
".validate": "newData.isBoolean()"
},
"$other": {
".validate": false
}
}
}
},
In the code for my android app I run these two lines: 在我的Android应用程序的代码中,我运行以下两行:
dataSnapshot.child("request").getRef().removeValue();
dataSnapshot.child("approved").getRef().removeValue();
What I find weird is that it allows me to remove the "approved" value but not the "request" value. 我觉得奇怪的是它允许我删除“已批准”值而不是“请求”值。 The dataSnapshot is a $requesterid.
dataSnapshot是$ requesterid。 If I run this line in the simulator and it allows the write:
如果我在模拟器中运行此行并允许写入:
/joinRequests/QV28VJYG/c1cef959-2dd3-4cab-8649-2b81892cffa6/request
The error I get in android studio is this: 我在android studio中得到的错误是这样的:
W/RepoOperation: setValue at /joinRequests/QV28VJYG/qRlJt4UIAcRVIe9VXoYVBa68tO43/request failed: DatabaseError: Permission denied
It must be something dumb that I'm doing but I can't imagine what it would be. 我必须做一些愚蠢的事,但我无法想象它会是什么。 Any help would be great, Thanks.
任何帮助都会很棒,谢谢。
newData is a snapshot that represent how data will look like after the operation took place. newData是一个快照,表示操作发生后数据的外观。
newData.hasChildren(['request'])
tells firebase to make sure that the request
node exists after the operation was executed. newData.hasChildren(['request'])
告诉newData.hasChildren(['request'])
在执行操作后确保request
节点存在。 Therefore, deletion of this node is prohibited. 因此,禁止删除此节点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.