【问题标题】:How to block user from writing to Firebase Database? Without changing all the other rules below如何阻止用户写入 Firebase 数据库?在不更改以下所有其他规则的情况下
【发布时间】:2021-06-11 20:27:04
【问题描述】:

我管理一个阻止列表,我希望阻止阻止列表中的用户写入/读取数据库(禁止)。但是,如果我在更高级别上编写此代码,则以下所有其他规则都不适用于不在阻止列表中的用户。有没有办法把它写在更高的级别而不是编辑下面的所有表格?

   {
   "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 firebase-realtime-database firebase-authentication firebase-security


    【解决方案1】:

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

    喜欢docs 说:

    .read 和 .write 规则自上而下工作,较浅的规则覆盖较深的规则。如果规则授予特定路径的读取或写入权限,则它还授予对其下所有子节点的访问权限。考虑以下结构:

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

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

    【讨论】:

      猜你喜欢
      • 2021-08-27
      • 2018-12-08
      • 2016-12-29
      • 1970-01-01
      • 2021-05-20
      • 2021-09-25
      • 1970-01-01
      • 2016-03-23
      • 2015-05-18
      相关资源
      最近更新 更多