How to allow one admin user to write a Firebase database?

I am trying to set up a Firebase database that I can write. Thus, the user does not have permission to write anything. But everyone can read it.

However, I could not establish rules for him. I have one admin user that I created using the Email / Password login and I know its UID. Say my UID is: dJrGShfgfd2

I tried these two methods, but they did not allow me to write to the database.

 { "rules": { "events": { ".read": true, ".write": "auth.uid === 'dJrGShfgfd2'" } } } 

.

 { "rules": { "users": { "$user_id": { ".read" : true, ".write": "$user_id === 'dJrGShfgfd2'" } } } } 

So, how do I allow only one user with a specific UID to write something to the database?

+5
source share
1 answer

This should work:

 { "rules": { ".read": true, ".write": "auth.uid === 'dJrGShfgfd2'" } } 

Everyone in the world will be able to read data, but only a user with the UID dJrGShfgfd2 (and processes access with administrator rights ) can write data.

+6
source

Source: https://habr.com/ru/post/1263116/


All Articles