【问题标题】:Firebase Security rules for admin to write and read everything in database管理员在数据库中写入和读取所有内容的 Firebase 安全规则
【发布时间】:2017-06-09 13:15:00
【问题描述】:

我正在努力让自己能够读写数据库中的所有内容。

尝试在 Firebase 模拟器中运行此程序时出现读取被拒绝错误。

{
  "rules": {

    ".read": "root.child('Admin').child('isAdmin').child('+$AUID').val() === true",

    "Admin": {
      "isAdmin": {
        "$AUID": {

          ".read": "$AUID === auth.uid",
          ".write": "$AUID === auth.uid",
          ".validate": "newData.hasChildren(['active'])",

          "active": {

            "active": "true"
          },
        },
      },
    },
}

【问题讨论】:

  • 将“+$AUID”更改为 $AUID。而且...您正在检查 $AUID: true 的键:值对,这不是有效的键:值对,至少在提供的规则中是这样。另外,与任何其他用户相比,“你自己”的定义是什么?

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


【解决方案1】:

如果您想让用户访问您的 Firebase,其访问级别由另一个节点中的值决定,这样的方法可能会起作用。 (未测试)

users
  uid_0
    is_admin:true  //your uid
  uid_1
    is_admin:false

和规则

rules
  ".read": "root.child('users').child(auth.uid).child('is_admin').val() == true"
  ".write": "root.child('users').child(auth.uid).child('is_admin').val() == true"

【讨论】:

  • 非常感谢。
猜你喜欢
  • 2020-11-22
  • 2022-11-11
  • 2021-06-24
  • 1970-01-01
  • 2020-05-27
  • 2019-01-10
  • 1970-01-01
  • 1970-01-01
  • 2016-09-16
相关资源
最近更新 更多