0

我已经在 Firebase 中实施了规则来限制对数据的访问,当我在 Firebase 验证器视图中模拟读/写权限时,就会授予权限。但是当我运行 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>')

因此,不授予对该路径的访问权限,但前提是我尝试获取一条特定消息。但是我怎样才能检索一个只包含通过验证的项目的数组呢?

4

1 回答 1

0

经过更多研究后,我发现我试图实现的目标在 Firebase 中是不可能的,所以我必须重组我的数据库以实现这种行为。有关更多信息,请参阅另一个 StackOverflow 帖子的链接: Firebase security rules for child items in arrays

于 2018-08-08T14:22:31.570 回答