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

Time:03-17

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.

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

CodePudding user response:

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.

  • Related