3
votes

here is my structure data

  • sampleApp

    • items

      • item1
        • title: pizza
        • price: 200/-
      • item2
        • title :burger
        • price: 120/-
    • users

      • user-1
      • user-2

Here is my rules

rules{
  ".write": true,
  "items":{
    ".read":"root.child(users).child(auth.uid).child(role).child(admin).val()===true"      
  }
}

My question is when user-1: " admin=true, user=true, superuser=true " total items child have to read. For another user-2: " admin=false, user=true, superuser=false " in this case only item1 has to read in items child.

How can I write the security rules for it?

1

1 Answers

5
votes

From my understanding, you would like to give read permission to any superuser OR admin.

You can use boolean logic in security rules like this:

rules{
   ".write": true,
   "items":{
      ".read":"root.child(users).child(auth.uid).child(role).child(admin).val()===true 
              ||"root.child(users).child(auth.uid).child(role).child(superuser).val()===true" "      
       }
    }

Hope it helps ;)