在Firebase规则中,如何在允许`.write`

时间:2016-11-03 12:17:40

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

如果STREET_ID的ID为“-K1234567”,则允许STREET_ADDRESS的写访问权

Firebase规则json:

 {
  "rules": {
    "$countries": {
      "STREET_ID": {
         ".read": "auth != null",
         "$PathKey": {
           ".write": "root.child('US/STREET_ADDRESS').hasChild(-K1234567)",
           ".validate": "newData.isString()"
         }
       },
       "STREET_ADDRESS": {
           ".read": "auth != null",
           ".write": "!data.exists()"
       },
  }
}

Firebase json:

  "UA": {
    "name": "Ukraine"
  },
  "AE": {
    "name": "United Arab Emirates"
  },
  "GB": {
    "name": "United Kingdom",
      "STREET_ID": {......    
  },
  "US": {
    "name": "United States",
      "STREET_ID": {
         "US/California/Orange County/Orange/3138 E Maple Ave": "-K1234567",
         "US/California/Orange County/Orange/3139 E Maple Ave": "-K12334rt"
        },
        "STREET_ADDRESS": {
          "-K1234567": {
              "path": "US/California/Orange County/Orange/3138 E Maple Ave",
              "values": {
                "call": false,
                "id": "",
                "start_date": "",
                "end_date": "",
                "type": "",
                "name": ""
              }
          }, 
            .............
        },

如您所见,“ - K1234567”是STREET_ADDRESS中的推送键和STREET_ID中的值,基本上用户只能在{{{}} STREET_ID中插入STREET_ADDRESS 1}}。

我读到newData并试着像这样应用它:

 ".write": "root.child('US/STREET_ADDRESS').hasChild(newData.val())",  

那不行或应该吗? 我怎样才能做到这一点?

0 个答案:

没有答案