Firebase 规则权限被拒绝,但为什么呢?

Firebase Rules permission denied but why?

这是我的规则:

{
  "rules": {
    "freecoinsrequest":{
      ".read": false,
        ".write": "
      newData.child('uid').val() == auth.uid 
       1. && (root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').val() < now - 10000 
       2. || !root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').exists())
       " ,
      "uid":{
        ".validate" : true
      },
        "$other":{
          ".write": false,
          ".validate": false
        }
    },
  }
}

因此用户应该只能在以下情况下写入路径:

我不明白为什么它在模拟器中被拒绝。当我取消注释 1 和 2 时,如规则所示,它起作用了。

谢谢。

在我的测试中,规则在 /users/$uid/server/lasttimetookfreecoins 存在时产生了预期的结果,但在不存在时失败了。颠倒条件的顺序固定为:

  newData.child('uid').val() == auth.uid 
    && (!root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').exists()
    || root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').val() < now - 10000)