How to set up admin user and common user in Firebase

Asked

Viewed 2,002 times

1

I have a web system that will be used by two different types of users, the administrator and the common.

There are some options that will only be available to the administrator (for example, register new users). How would I do this setting using firebase? since the user management itself consists of only 'login' and 'password' and does not offer me the possibility to add new fields such as 'user type''.

I have read the firebase documentation and there is no reference to it in itself.

  • Your question is not clear, exactly what context is the system intended for (mobile, web)? Is this about a login system or about administration and authentication in Firebase? "Generic" questions tend to receive "generic answers"... this goes against the community q seeks to bring a more "qualified knowledge sharing".

  • If it’s only in Firebase it might help: https://firebase.google.com/docs/auth/users

  • Hello @Lauromoraes, I edited the question so that it is more detailed.

1 answer

3

The Firebase Auth allows only 'login' and 'password' as you said, but the Realtime Database and the Cloud Firestore allow you to keep much more than that.

When creating a user, store your data in one of the database services (Realtime Db or Firestore) through the user’s logged in uid. To get this uid just use:

var uid = firebase.auth.currentUser.uid;

And then you can store in Realtime Database with the user type:

firebase.database.ref('usuarios').child(uid).set({
     login:login,
     senha:senha,
     userType:"Administrador"
});

Having user data stored makes it easier for you to create conditions to check which user has access to the particular option of your system.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.