【问题标题】:How to allow one admin user to write Firebase Database? Without changing all the other rules below如何允许一名管理员用户编写 Firebase 数据库?在不更改以下所有其他规则的情况下
【发布时间】:2021-08-27 22:41:18
【问题描述】:

我想保留我关于用户和玩家的特定规则,但我想要一个优先规则,我们允许管理员用户不受限制地编写,它应该是 "OR" ,表示您是管理员或下面的规则。 (没有开始编辑下面的每个表)

  "rules": {   
      "scores": {
          "$sid": {
                ".read": true,
                ".write": "root.child('game').child($sid).child(auth.uid).exists()&& 
                auth!=null"
              }
            },...

【问题讨论】:

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


    【解决方案1】:

    您可以为管理员用户添加更高级别的规则,例如,如果您通过其 UID 识别管理员,您可以这样做:

    {
      "rules": { 
        ".write": "auth.uid === 'theuidofheadmin'",
        "scores": {
          "$sid": {
            ".read": true,
            ".write": "root.child('game').child($sid).child(auth.uid).exists()&& 
                      auth!=null"
          }
        },...
    

    所以现在管理员对根目录下的任何东西都有写权限,你不能再把它们拿走,但其他人仍然需要满足每个特定节点的要求。

    另见:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-24
      • 2017-06-05
      • 2020-05-27
      • 1970-01-01
      • 2020-11-22
      • 2017-07-16
      • 2023-03-21
      • 2021-11-12
      相关资源
      最近更新 更多