0

I setup rules on Firebase like this:

 "Data": {
  ".read": true,
    "data1": {
      ".write": "root.child('Permissions').child(auth.uid).val() == 'admin'",
      ".read": true
    },
    "data2": {
      ".write": "root.child('Permissions').child(auth.uid).val() == 'admin'",
      ".read": "root.child('Permissions').child(auth.uid).val() == 'admin'"
    }
}

and in my code, I want that when I read the node "Data", and data return should only contain "data1" node if users do not have "admin" permission, else both "data1" & "data2" are returned. Currently, when I get child "Data", both are return.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Hoang Trung
  • 263
  • 4
  • 15
  • what if you remove the `".read": true` from the Data node? – mbehzad Sep 07 '17 at 12:55
  • then it will be permission deny when I try to read Data node – Hoang Trung Sep 07 '17 at 13:08
  • from another question (https://stackoverflow.com/questions/14296625/restricting-child-field-access-with-security-rules) it seems that firebase doesn't allow "filtering" the data via the permissions. – mbehzad Sep 07 '17 at 13:25

1 Answers1

1

According to the docs:

{
   "rules": {
     "foo": {
       // allows read to /foo/*
       ".read": "data.child('baz').val() === true",
       "bar": {
         /* ignored, since read was allowed already */
         ".read": false
       }
      }  
    }
}

if you allow read or write on a higher level (".read": true), it ignores other rules down the tree (".read": "root.child('Permissions').child(auth.uid).val() == 'admin'").

mbehzad
  • 3,758
  • 3
  • 22
  • 29