我不明白为什么 firebase 不让我做这个特定的写作。我觉得我在模拟器中做同样的事情并且它在那里工作。以下是我对此部分的安全规则。
"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
}
}
}
},
在我的 android 应用程序代码中,我运行了这两行:
dataSnapshot.child("request").getRef().removeValue();
dataSnapshot.child("approved").getRef().removeValue();
我觉得奇怪的是它允许我删除“批准”值而不是“请求”值。 dataSnapshot 是一个 $requesterid。如果我在模拟器中运行这一行并且它允许写入:
/joinRequests/QV28VJYG/c1cef959-2dd3-4cab-8649-2b81892cffa6/request
我在android studio中得到的错误是这样的:
W/RepoOperation: setValue at /joinRequests/QV28VJYG/qRlJt4UIAcRVIe9VXoYVBa68tO43/request failed: DatabaseError: Permission denied
我正在做的事情一定很愚蠢,但我无法想象它会是什么。任何帮助都会很棒,谢谢。
最佳答案
newData 是一个快照,表示操作发生后数据的样子。
newData.hasChildren(['request'])
告诉 firebase 在执行操作后确保 request
节点存在。因此,禁止删除该节点。
关于android - Firebase 写入权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38337914/