Firebase Database Rules for groups

前端 未结 2 761
盖世英雄少女心
盖世英雄少女心 2021-01-01 05:56

I have this Firebase DB which could be changed if necessary:

The JSON of that DB is:

{
  \"groups\": {
    \"1\": {
      \"name\": \"G1\",
         


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-01 06:13

    What if you try nested rules for the "points" and "visits" levels:

    "groups": {          
      "$groupId": {
        ".read": "root.child('userGroups').child(auth.uid).child($groupId).exists()",
        ".write": "root.child('userGroups').child(auth.uid).child($groupId).val() == 'admin'",
        "points": {
          ".write": "root.child('userGroups').child(auth.uid).child($groupId).val() != 'readonly'"
        },
        "visits": {
          ".write": "root.child('userGroups').child(auth.uid).child($groupId).val() != 'readonly'"
        }
      }
    },
    "users": {
      "$userId": {
        ".read": "auth != null",
        ".write": "auth != null && 
                  $userId === auth.uid && 
                  newData.val() != null"
      }
    },
    "userGroups": {
      "$userId": {
        ".read": "auth != null",
        ".write": "auth != null && 
                   data.child(auth.uid).val() === 'admin' && 
                   newData.val() != null"          
      }
    }
    

提交回复
热议问题