【问题标题】:Firebase Security: Permission Denied Until Page RefreshFirebase 安全:在页面刷新之前权限被拒绝
【发布时间】:2015-06-03 07:29:54
【问题描述】:

我有一个单页应用程序,当我点击进入我的报告页面时,firebase 显示permission_denied: Client doesn't have permission to access the desired data。但是,如果我刷新我的页面,firebase 会授予我访问权限。

这是我的安全规则

{
"rules": {
    "signup": {
      ".read": false,

      "$id": {
        // you can add new data but not change old data
        ".write": "!data.exists()"
      }
    },
    "users": {
      ".read": false,

      "$uid" : {
        // you can add new data but not change old data
        ".write": "!data.exists()",
        ".read": "auth.uid == $uid"
      }
    },
    "reports": {
      "$reportId": {
        ".read": "root.child('users').child(auth.uid).child('reportsToView').hasChild($reportId)",
        ".write": "root.child('users').child(auth.uid).child('reportsToEdit').hasChild($reportId)"
      }
    }
}

}

【问题讨论】:

  • 听起来问题出在您的身份验证或导航方式上。你能提供重现问题的最少代码吗?
  • 感谢@FrankvanPuffelen 的输入,您帮助我找到了答案。
  • 制作 mcve 的众多原因之一:通过减少您的应用程序,您通常会自己找到解决方案。这类似于橡皮鸭调试。感谢分享答案!一旦 SO 允许,不要忘记接受它。

标签: javascript security firebase angularfire


【解决方案1】:

我有两个 firebase refs new Firebase("https://domain.firebaseio.com/")。一个经过身份验证,另一个没有。我只需传递我的单个 firebase 引用即可解决问题。

【讨论】:

  • 多个 Firebase 引用在这里无关紧要。只要您没有摆弄上下文,调用 new Firebase(...) 仍然会重新使用身份验证凭据 - 如果您不知道这意味着您没有。因此,您通过更改事件的异步顺序而不是通过传递 ref 意外地解决了这个问题。
猜你喜欢
  • 2016-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-15
  • 2017-12-26
相关资源
最近更新 更多