如何为包含成员和组的数据库编写firebase规则?

时间:2018-06-04 15:56:18

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

我有一个带有members根和groups根的firebase数据库,组root看起来像这样:

"groups": {
    "test-group" : {
      "name" : "Test Group"
      "members" : {
        "5HWOQlahMAdKWJ6D2bUCFk273te2" : {
          "admin" : true
        }
      },
    }
  }

并且成员root看起来像这样:

"members": {
    "5HWOQlahMAdKWJ6D2bUCFk273te2" : {
      "photo" : "photourl",
      "username" : "Harry Banda",
      "email" : "harrybanda7@gmail.com",
      "groups" : {
        "test-group" : {
          "admin" : true
        }
      }
    }
  }

我的规则:

{
  "rules": {
    "groups": {
      ".read": "auth != null",
      ".write": "auth != null"
    },
    "members": {
      "$uid": {
        ".read": "auth != null && auth.uid == $uid",
        ".write": "auth != null && auth.uid == $uid"
      }
    }
  }
}

如何编写规则,以便只有"admin" : true的经过身份验证的成员才能读取和写入他们调节的组的数据?

0 个答案:

没有答案