【问题标题】:Firebase / VueFire Rules pass validator but returns no resultsFirebase / VueFire 规则通过验证器但不返回结果
【发布时间】:2019-01-15 19:29:30
【问题描述】:

我在 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 在通配符 ($) 上存在问题?

有没有其他人经历过类似的事情?或者有什么想法?

更新:我在尝试访问消息数组时发现验证失败。

代码sn-p:

// 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>')

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

【问题讨论】:

  • 请包含您用于测试的代码和/或模拟值。
  • Query based security rules 可以是一个解决方案。
  • 感谢@AndréKool 的回复,看起来很有趣。在重组我的数据库之前,我会试一试。

标签: firebase vuefire


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    • 2018-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多