Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to allow only admin user can access Firebase realtime database?

I’m new to firebase,
I am trying to have a Firebase realtime database where only the admin can write the data, the user only can read the data.

I have seen the documentation that uses log-in(authentication) logic to control it.

I’m not really sure I can implement like the below code, only admin uid can write the data, if that work how do I find the admin uid(xxxxxxxx)?. Thanks.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

Yes, that’s totally valid if you want to allow that 1 user only to write data. auth.uid is UID of user attempting to write data and that checks if it matches your Admin ID.

If there can be multiple admins, custom claims are useful too.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading