How to configure admin user and common user in Firebase

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 made available to the administrator (for example, register new users). How would I do this setup 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 this in the firebase documentation itself.

Author: Leticia Fatima, 2018-03-29

1 answers

Firebase Auth only allows 'login' and 'password' as you said, but Realtime Database and Cloud Firestore allow you to save a lot more than that.

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

var uid = firebase.auth.currentUser.uid;

And then you can store in Realtime Database with User Type:

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

Having the data from the stored user, it becomes easier for you to create conditions to verify which user has access to the particular option of your system.

 3
Author: Rosário Pereira Fernandes, 2018-03-29 06:24:18