Firebase规则-身份验证用户不断在控制台的模拟器上被拒绝

时间:2019-03-04 09:01:03

标签: firebase firebase-realtime-database firebase-authentication

我面临的问题是,即使我有Auth用户并且我认为规则正确,模拟器仍然拒绝。

这是我的Firebase规则:

   {
  "rules": {
    "jobs": {
       "$uid": {
         ".read": "$uid === auth.uid",
         ".write": "$uid === auth.uid"
       }
     }
   }
}

还有我的Firebase数据库

"jobs" : {
    "5HSJNaWoBFbU8nPSy3zND0gH6n92" : {
      "collected" : "no",
      "collection date" : "10/03/19",
      "consignee" : "Annie Mattey",
      "delivered" : "no",
      "email" : "a_________________",
      "freight" : "2 Pallets",
      "pod" : "pick up at 9am",
      "reference" : "RE0003",
      "shipper" : "Thames Link"
    },
    "7pyXtGOULNNQSpsfaVeCjYynn6D3" : {
      "collect" : "no",
      "collection date" : "10/03/19",
      "cosignee" : "Molly Warner",
      "delivered" : "no",
      "delivery date" : "15/03/19",
      "email" : "mo______________",
      "freight" : "9 Pallets",
      "pod" : "Pick up at 9.30am at B____",
      "reference" : "RE0001",
      "shipper" : "Transport"
    },
     "vzWxCUeGAcNesru9iqyYTb9YQ0D3" : {
      "collected" : "no",
      "collection date" : "05/03/19",
      "consignee" : "test1",
      "delivered" : "no",
      "delivery date" : "10/03/19",
      "email" : "email@test.co.uk",
      "freight" : "3 pallets",
      "pod" : "pick up at 9am on friday",
      "reference" : "RE0004",
      "shipper" : "testshipper"
    }
  }

但是,在Firebase控制台中使用模拟器时,我在使用Auth UID时仍会收到此消息:

Type    read
Location    /
Data    null
Auth    { "provider": "anonymous", "uid": "5HSJNaWoBFbU8nPSy3zND0gH6n92" }
Admin   false

我的规则错了吗?我不确定为什么会一直否认。

2 个答案:

答案 0 :(得分:0)

似乎您正在运行模拟器以从根目录/而不是该$ uid的job / uid位置读取

答案 1 :(得分:0)

您没有正确使用模拟器,需要在location内键入要测试的特定位置“ jobs/sampleJobId/”,然后使用Authenticated进行尝试,然后没有,那应该工作。