5

在我的 Firebase 安全规则中,我希望匿名用户能够读取除一个字段 ( secret_field) 之外的任何内容:

{
  "rules": {
    ".read": true,
    ".write": "auth != null",
    "stuff" : {
      "$stuffID" : {
        "secret_field" : {
           ".read" : "auth != null"
        }
      }
    }
  }
}

但是,在 Firebase 中,如果任何读取规则secret_field评估为真,则授予读取访问secret field权限。

有没有办法扭转这种行为?(如果任何读取规则secret_field评估为假,则禁止读取访问)

4

1 回答 1

10

您无法逆转该行为,但您可以通过为公共字段引入“容器”并将 .read 设置为 true 来解决此问题。例如:

{
  "rules": {
    "stuff" : {
      "$stuffID" : {
        "public" : {
          ".read": true
        },
        "secret_field" : {
          ".read" : "auth != null"
        }
      }
    }
  }
}

然后每个人都可以访问 .../public/ 下的所有内容,但 .../secret_field 只有经过身份验证的用户才能访问。

于 2013-01-30T03:19:04.473 回答