1

I'm having trouble to write Firebase database rules. I would like to give write permission to only one user i.e admin user. All others will have read permission.

Please help me to write a Firebase database rule to restrict other users to write.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

3 Answers3

2
"rules":{
  "users" : {
     "$uid" : {
        ".read" : "auth!=null",
        ".write" : "$uid === adminUID"
      }
   }
}

This will help you

Prags
  • 811
  • 5
  • 17
1
{
  "rules": {
    "users": {
      "$uid": {
        ".write": "$uid === auth.uid"
      }
    }
  }
}

Just replace auth.uid with the uid of the admin you want to be able write to the database.

You can read the documentation here: https://firebase.google.com/docs/database/security/

Jean Eric
  • 73
  • 2
  • 11
1

I assume your access rights apply to the entire JSON data and admin is the one who has access to firebase console. So, below rule will work,

{
  "rules": {
    ".read": true,   // (or) ".read": "auth != null"
    ".write": "auth != null && auth.token.isAdmin == true"
  }
}
Nagaraj N
  • 457
  • 6
  • 13