Ionic Firebase AngularFire2 User roles and database

Hi guys,

I’m currently developing an app that requires two user types, lets say Leaders and Employees. I’d like to make use of Firebase authentication and Firestore. I have Firebase authentication working but I can’t seem to map the userID Firebase authentication generates to my User collection in my database.

I’d like to have the user sign up with Email and password, then for the userID, the email and some other details to be saved to the User collection in the database.

I currently have this in my auth provider:

export class AuthProvider {
  user: Observable<firebase.User>;
  userID = firebase.auth().currentUser.uid;

  constructor(private afAuth: AngularFireAuth) {
    this.user = afAuth.authState;

  registerUser(email: string, password: string) {
      .createUserWithEmailAndPassword(email, password)
      .then(user => {
        console.log('Success, user created', user);
      .catch(err => {
        console.log('Something went wrong:',err.message);

They are getting added but I can’t get the “uid” to add to the collection in the database due to the “uid” being null. I believe I have to get the “uid” when the user is created but I’m unsure how.

If anyone could help and also point me in the direction of good tutorials involving Ionic and Firebase/Firestore it would be appreciated.


This is much simpler with Angular Firestore. (angularfire2)

Can’t you see I’m trying to use that?

Why are you mixing idioms then?

Sorry, I’m new. I trying to figure out how to do it from many sources. Recording to the database is what I’m stuck on. I still use Firebase auth to signup and login right?

This is the first line of the AngularFire auth documentation.

AngularFireAuth.authState provides you an Observable<firebase.User> to monitor your application’s authentication State.

This is a couple years old, but is a great place to start.
The firebase docs, or angularFire docs as @AaronSterling points out, are where you want to end up but for someone new they’re pretty intense and more confusing than they are helpful (at least they were for me)