【问题标题】:Can't get data from firebase. Authorization denied无法从 Firebase 获取数据。授权被拒绝
【发布时间】:2017-03-09 08:47:35
【问题描述】:

我仍然从 firebase 开始,我正在使用 angularfire 进行连接。 我能够使用谷歌作为提供者成功地进行身份验证,我使用我的帐户登录并取回了我的用户详细信息,包括 uid 和图像,但是,当我尝试检索我得到的任何数据时:permission_denied at /series: Client doesn't have permission to access the desired data. 我也尝试了模拟器并遇到了同样的问题。

这是我的数据库:

我的规则:

我在模拟器中输入的数据。我在应用程序中使用 google 登录后得到了 uid:

以及使用模拟器后的结果:

我从这里获得我的 UID:(身份验证选项卡)

我应该做什么但不做什么

【问题讨论】:

    标签: firebase firebase-authentication


    【解决方案1】:

    终于找到答案了。正如卡坦特所写的

    没有授予读取权限,因为 .read 默认为 false

    我需要做的就是".read": "auth != null"

    所以新规则是:

    {
      "rules": {
        "series": {
          ".read": "auth != null", << THAT WAS MISSING
          "$uid": {
            ".read": "$uid === auth.uid",
            ".write": "$uid === auth.uid"
          }
        }
      }
    }
    

    【讨论】:

    • 请注意,使用这些规则,每个人都可以读取/series 下的所有数据。 $uid 下的 .read 规则不会剥夺任何人的许可。有关详细信息,请参阅 Firebase 文档:firebase.google.com/docs/database/security/…
    猜你喜欢
    • 2019-04-27
    • 2017-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    • 2017-03-10
    • 2019-11-15
    相关资源
    最近更新 更多