Firebase安全规则 - 模拟器和代码之间的行为差 异

问题描述 投票:0回答:1

数据

"directChat" : {
  "creator" : {
    "1-L6HQZZSvJ0aarUmXdtN" : {
      "ID" : "XXX",
      "fbID" : "YYY",
      "name" : "Hari"
    }
  },
  "target" : {
    "1-L6HQZZSvJ0aarUmXdtN" : {
      "ID" : "ZZZ",
      "fbID" : "AAA",
      "name" : "John Doe"
    }
  }
}

安全规则

"directChat": {
  "creator": {
    "$cID": {
      ".write": "data.val() == null && auth != null && newData.parent().parent().parent().child('directChat/creator/' + $cID + '/ID').val() == auth.uid",
      ".read": "auth != null && data.child('revealed').val() == true && root.child('directChat/target/' + $cID + '/ID').val() == auth.uid"
    },
    ".read": "auth != null && auth.uid == query.equalTo && query.orderByChild == 'ID'"
  }
}

Firebase模拟器

Simulation type - Read
Ref - /directChat/creator/1-L6HQZZSvJ0aarUmXdtN/
UID - XXX

async runTests(){
  var creatorIsMe = await firebase.database().ref('directChat/creator/1-L6HQZZSvJ0aarUmXdtN/').once('value')
  console.warn('value1', creatorIsMe)
}

模拟失败,这是预期的行为,但我的代码返回快照!我错过了什么?

firebase firebase-realtime-database firebase-security
1个回答
1
投票

在浪费了大约半天后发现它。它由于离线持久性。

我开始使用像auth!= null这样的规则,它同步到脱机缓存。当我更改规则以向数据添加更多限制时,数据不会同步,并且它会使离线返回结果。

多糟糕的火基! Firebase脱机持久性应该将Permission denied错误视为由于脱机/其他原因无法访问服务器数据。

最好不要在开发模式下启用脱机持久性。

© www.soinside.com 2019 - 2024. All rights reserved.