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.
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.
"rules":{
"users" : {
"$uid" : {
".read" : "auth!=null",
".write" : "$uid === adminUID"
}
}
}
This will help you
{
"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/
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"
}
}