如何允许一位管理员用户编写 Firebase 数据库?不改变以下所有其他规则

问题描述

我想保留关于用户和玩家的特定规则,但我想要一个允许管理员用户无限制地编写的优先规则,它应该是“OR”,这意味着您要么是管理员,要么是规则如下。 (无需开始编辑下面的每个表格)

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

解决方法

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

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

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

另见: