Ahmed
Ahmed

Reputation: 23

Firebase Security rules for admin to write and read everything in database

i am trying to allow my self to be able to read and write everything in the database.

i am getting a read denied error when trying to run this in the firebase simulator.

{
  "rules": {

    ".read": "root.child('Admin').child('isAdmin').child('+$AUID').val() === true",

    "Admin": {
      "isAdmin": {
        "$AUID": {

          ".read": "$AUID === auth.uid",
          ".write": "$AUID === auth.uid",
          ".validate": "newData.hasChildren(['active'])",

          "active": {

            "active": "true"
          },
        },
      },
    },
}

Upvotes: 2

Views: 4799

Answers (1)

Jay
Jay

Reputation: 35657

If you want to give a user access to your Firebase whose level of access is determined by the value in another node, something like this may work. (Not tested)

users
  uid_0
    is_admin:true  //your uid
  uid_1
    is_admin:false

and rules

rules
  ".read": "root.child('users').child(auth.uid).child('is_admin').val() == true"
  ".write": "root.child('users').child(auth.uid).child('is_admin').val() == true"

Upvotes: 8

Related Questions