我在Firebase中实现了规则,以限制对数据的访问,并且当我在Firebase Validator视图中模拟读取/写入权限时,将授予该权限。但是当我运行VueFire时,没有结果返回。
这是数据库的结构:
<firebase-id>:
-chat:
-messages:
- message1
- message2
- message3
这是我从Firebase获得的规则:
{
"rules": {
"chat": {
"messages": {
"$message": {
".read": "auth != null && data.child('uid').val() == auth.uid",
".write": "auth != null && data.child('uid').val() == auth.uid"
}
}
}
}
}
我已登录并通过身份验证,但未收到任何结果。
我尝试通过身份验证时授予访问权限,当我将规则放在聊天级别(消息级别)上时有效,但是如果我将规则放在$ message级别上则无效,这表明VueFire的通配符($)有问题?
有没有其他人经历过类似的事情?或有任何想法出什么问题了?
更新:我发现尝试访问邮件数组时验证失败,就像我正在尝试的那样。
代码段:
// Generate ref to messages fails validation
export const messages = firebaseRef.child('chat').child('messages');
// Generate ref to specifi message create by user passes validation
export const messages = firebaseRef.child('chat').child('messages').child('<message id>')
因此,仅当我尝试获取一条特定消息时,才授予对此路径的访问权限。但是,如何检索仅包含通过验证的项目的数组?
答案 0 :(得分:0)
经过更多研究,我发现我试图实现的目标在Firebase中是不可能的,因此我必须重组数据库以实现此行为。有关更多信息,请参见另一个StackOverflow帖子的链接: Firebase security rules for child items in arrays