【问题标题】:confusing with firebase rules (read and write)与 firebase 规则混淆(读写)
【发布时间】:2018-02-17 23:54:52
【问题描述】:

我正在使用 Firebase 制作 IOS 应用,但似乎遇到了一个奇怪的问题。

这是我目前对数据库的规则:

{
"rules": {
".read": "auth == null",
".write": "auth != null"
    }
}

在主应用程序中,我能够以用户或非用户身份读写数据库。 我使用第二个应用程序通过远程编辑我的数据库。他们有相同的firebase项目,所以相同的数据库。 我在第二个应用程序上注册,但我无法在数据库上读写。 控制台说“权限被拒绝”。

如果我只是将我的数据库规则更改为:

 {
"rules": {
".read": "auth != null",
".write": "auth != null"
      }
}

我可以在上面读写。

请帮助我理解它。

【问题讨论】:

  • 由于@creativecreatorormaybenot 回答".read": "auth == null" 将只允许在用户登录时读取数据。您更有可能希望使用".read": true,它允许两者经过身份验证和未经身份验证的用户读取数据。
  • @FrankvanPuffelen 非常感谢您的回答!允许 auth 和 unauth。这正是我正在寻找的!我是 Firebase 和 Firebase 规则的新手...实际上无法投票赞成您的答案:/

标签: ios firebase firebase-realtime-database firebase-security


【解决方案1】:
{   
 {
   "rules": {
   ".read": "auth == null",
   ".write": "auth != null"
  }
}

在第一个规则案例中,.read 设置为 auth == null,这意味着您只有在身份验证/登录时才能读取数据库。

.read 更改为auth != null 意味着您只能在经过身份验证时从数据库中读取数据。

更多信息请见here in the Firebase documentation

【讨论】:

    【解决方案2】:

    由于@creativecreatorormaybenot 回答“.read”:“auth == null”将只允许在用户未登录时读取数据。

    如果您想允许经过身份验证和未经身份验证的用户读取您要使用的数据:

    ".read": true
    

    【讨论】:

      猜你喜欢
      • 2018-04-30
      • 2010-11-24
      • 2016-04-01
      • 1970-01-01
      • 2017-12-13
      • 1970-01-01
      • 1970-01-01
      • 2017-03-13
      • 1970-01-01
      相关资源
      最近更新 更多