我正在使用Firebase开发应用程序。我在Firebase上具有以下数据结构:
{
rules: {
"version": {
"threads": {
"$thread": {
"noticeList": {
".read": true,
".write": true
},
"messages": {
".read": "root.child('version/threads/' + $thread + '/users/' + auth.uid).exists()",
".write": "root.child('version/threads/' + $thread + '/users/' + auth.uid).exists()"
},
"$other": {
".read": "auth != null",
".write": "auth != null"
}
}
}
}
}
每个线程都有一个子节点/users/
,我想制定一个规则,只有包含的用户才能在该线程中读写消息。
noticeList
添加新消息时,我还必须访问另一个条件。但是,这些规则不起作用。如果“ $ thread”中还有其他节点规则,使用时我将无法获得任何响应
firebase.child("version/threads/" + $thread + "/noticeList").once("value", function(snapshot) {});
或者
firebase.child("version/threads").once("value", function(snapshot) {});
我该如何解决?
谢谢
您的查询从以下位置开始:
firebase.child("version/threads/" + $thread + "/noticeList")
执行此查询时,Firebase会检查用户是否有权读取该节点。在这种情况下,用户没有使用,因此查询失败。
当涉及到Firebase安全规则时,这是人们常犯的错误。Firebase文档将其解释为“规则不是过滤器”,这正是您要尝试执行的操作。
不幸的是,对于您的情况,文档还解释了“规则级联”。从本质上讲,这意味着,如果您授予用户对的读取访问权限noticeList
,则不能在较低级别上取消读取访问权限。
使此工作最简单的方法可能是为每个用户提供他们自己可以访问的通知索引。
version
threads
$thread
userNoticeList
<userid1>
<messageid1>: true
<messageid2>: true
<userid2>
<messageid1>: true
<messageid3>: true
这是相当典型的数据非规范化。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句