【问题标题】:Firebase Security Rules?Firebase 安全规则?
【发布时间】:2016-06-27 13:49:42
【问题描述】:

我似乎很难遵守 Firebase 安全规则。我已经阅读了指南,但模拟器结果描述性不够(如果我们可以将鼠标悬停在一个节点上,然后会弹出一个按钮,我们可以在其中更新规则会更容易)。

这是我的结构的样子:

chats
  - randomChatId01
    - name: "awesome chat"
    - members:
        - userId01 : true
        - userId02 : true
  - randomChatId02
    - members:
        - userId02 : true
  - randomChatId03
    - members:
        - userId01 : true
        - userId02 : true
  - ...

我只希望用户能够读取节点的子节点members包含经过身份验证的用户的auth.uid的聊天节点。

所以在这种情况下,如果 userId01 已登录,她将只有 randomChatId01randomChatId03 的读取权限。

这是我的规则:

{
    "rules": {

        "chats": {

          "$chat": {
            ".read": "data.child('members').val().contains(auth.uid)"
          }
        }
    }
}

但它在模拟器中返回以下内容:

Attempt to read /chats with auth={"provider":"anonymous","uid":"eF4ztDEXz7"}
    /
    /chats

No .read rule allowed the operation.
Read was denied.

【问题讨论】:

    标签: json node.js firebase firebase-security firebase-authentication


    【解决方案1】:

    这是因为 Firebase 安全规则是在您读取的位置进行评估的。

    您正在尝试阅读/chats。用户没有/chats的读取权限,操作直接失败。

    如果您将/chats/randomChatId01 读作userId01,它将成功。

    这在文档部分rules are not filters 中有介绍。也可以在这里查看 Michael Lehenbauer 的回答:Restricting child/field access with security rules

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-19
      • 2020-09-06
      • 2016-07-16
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 1970-01-01
      相关资源
      最近更新 更多