代码之家  ›  专栏  ›  技术社区  ›  Chris

Firebase实时数据库安全性无法读取闭包

  •  0
  • Chris  · 技术社区  · 7 年前

    我正在firebase中编写一个安全规则,以验证帖子是否存在或组是否存在。我完全理解安全规则不是过滤器,我不是将其用作过滤器,而是作为验证指标。这是我试图执行的规则。。。

        "notifications": {
      ".read": "auth !== null",
      ".write": "auth !== null",
      ".indexOn": ["post_ID", "group_ID"],
      "$userID": {
        "$notifID": {
          ".validate": "newData.hasChildren(['has-seen', 'end-time', 'time', 'user_ID', 'username']) && $userID !== newData.child('sender_ID').val() && (root.child('groups').child(newData.child('group_ID').val()).exists() || root.child('follower-feed-storage').child(newData.child('post_ID').val()).exists())",
          ".write": "auth.uid !== $userID && !data.exists()",
        }
      }
    },
    

    显然,规则应该评估haschilds和$userID!==新建数据。子项('user\u ID')。val()条件正确。但是,何时应计算&之后的最后一个表达式&在括号内,它将根据括号内的第一个条件成功或失败,并且不执行or运算符并计算第二个表达式。很明显,我的语法有问题,但我无法理解。提前感谢您的帮助。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Bryan Massoth    7 年前

    您必须通过 string .child 所以如果 newData.child('group_ID').val() 计算结果为 null undefined ,则它将失败。尝试将结果转换为 一串 或者在查找之前测试是否存在。(我推荐后者。)

    (newData.child('group_ID').exists() && root.child('groups').child(newData.child('group_ID').val()).exists())