【问题标题】:Security rules causes always getting "Permission denied"安全规则导致总是得到“权限被拒绝”
【发布时间】:2016-06-24 13:21:42
【问题描述】:

我觉得 Firebase 3 安全规则有问题。

我的规则如下所示:

{"rules":
  {
    "pages": {
      ".read": true,
      "$pageId": {
        ".read": true,
        ".write": "root.child('adminUsers').hasChild(auth.uid)"
      }
    },
    "adminUsers": {
      ".read": false,
      ".write": false
    }
  }
}

尝试添加设置页面对象

firebase.database().ref('/pages/-KL1TmkWWNUYsMqvTw1E').set({slug: 'rule'})

收到此错误(即使 /adminUsers/-XXXX = true 其中 -XXXX 是我的用户 ID):

FIREBASE 警告:设置在 /pages/-KL1TmkWWNUYsMqvTw1E 失败:permission_denied

".write": "root.child('adminUsers').hasChild(auth.uid)" 更改为".write": true 后,它起作用了。但这不是我想要的。

用规则模拟器测试了同样的东西,一切正常。我迷路了。

【问题讨论】:

  • 您能否向我们展示您的树的一些数据,以便我们准确了解它的结构?您在数据库选项卡上有一个导出到 JSON 选项,以方便操作。

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


【解决方案1】:

感谢@adolfosrs 要求我将数据库导出为 JSON

我发现我用引号包裹了userId,这导致了问题

{
  "adminUsers" : {
    "\"9hIokhGbBDfcvdQAPIoM7QcDS3g5\"" : true
  },
  "pages" : {
    "-KL1TmkWWNUYsMqvTw1E" : {
      "slug" : "xxx"
    }
  }
}

【讨论】:

    猜你喜欢
    • 2020-03-22
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    • 2016-01-19
    • 1970-01-01
    • 2021-02-13
    相关资源
    最近更新 更多