【问题标题】:Firebase Rules permission denied but why?Firebase 规则权限被拒绝,但为什么?
【发布时间】:2017-09-13 22:48:05
【问题描述】:

这是我的规则:

{
  "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
        }
    },
  }
}

因此,只有在以下情况下,用户才能写入路径:

  • JSON 包含“uid”作为键,他的 uid 作为值
  • 他没有在 10 秒前写入服务器/lasttimetookfreecoins 或
  • 他从未写信给服务器/lasttimetookfreecoins

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

谢谢。

【问题讨论】:

    标签: firebase firebase-realtime-database firebase-security


    【解决方案1】:

    在我的测试中,规则在/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)
    

    【讨论】:

      猜你喜欢
      • 2020-08-16
      • 1970-01-01
      • 2016-11-27
      • 1970-01-01
      • 2020-10-18
      • 2019-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多