如何阻止用户写入 Firebase 数据库?在不更改以下所有其他规则的情况下

How to block user from writing to Firebase Database? Without changing all the other rules below

我管理一个阻止列表,我希望阻止列表中的用户writing/reading 访问数据库(禁止)。但是如果我在更高的级别上写这个,下面的所有其他规则都不适用于不在阻止列表中的用户。有没有办法仍然在更高层次上编写它而不是编辑下面的所有表格?

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

不幸的是,Firebase RealtimeDatabase 规则以级联方式工作:

就像docs说的那样:

.read and .write rules work from top-down, with shallower rules overriding deeper rules. If a rule grants read or write permissions at a particular path, then it also grants access to all child nodes under it. Consider the following structure:

这意味着如果您在父节点中允许或拒绝,它将覆盖子节点规则。在您的情况下,阻止会起作用,但如果有人没有被阻止,则无论您为它们编写什么规则,他都将被允许用于所有子节点。

您需要将其与 || 运算符集成到每个子节点。