# Ionic Firebase AngularFire2 User roles and database

**URL:** <https://forum.ionicframework.com/t/ionic-firebase-angularfire2-user-roles-and-database/127309>\
**Category:** ionic-v3\
**Created:** [April 9, 2018, 1:18am UTC](https://forum.ionicframework.com/t/ionic-firebase-angularfire2-user-roles-and-database/127309 "2018-04-09T01:18:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![benmcm1994](https://avatars.discourse-cdn.com/v4/letter/b/e9bcb4/32.png) [@benmcm1994](https://forum.ionicframework.com/u/benmcm1994)\
**Post date:** [April 9, 2018, 1:18am UTC](https://forum.ionicframework.com/t/ionic-firebase-angularfire2-user-roles-and-database/127309/1 "2018-04-09T01:18:24Z")

</div>

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:

```auto
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) {
    this.afAuth
      .auth
      .createUserWithEmailAndPassword(email, password)
      .then(user => {
        firebase.firestore().collection('users').doc(this.userID).set(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.

Thanks.

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [April 9, 2018, 1:20am UTC](https://forum.ionicframework.com/t/ionic-firebase-angularfire2-user-roles-and-database/127309/2 "2018-04-09T01:20:17Z")

</div>

This is much simpler with Angular Firestore. (angularfire2)

---

<div class="post-metadata">

**Author:** ![benmcm1994](https://avatars.discourse-cdn.com/v4/letter/b/e9bcb4/32.png) [@benmcm1994](https://forum.ionicframework.com/u/benmcm1994)\
**Post date:** [April 9, 2018, 1:51pm UTC](https://forum.ionicframework.com/t/ionic-firebase-angularfire2-user-roles-and-database/127309/3 "2018-04-09T13:51:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [April 9, 2018, 1:53pm UTC](https://forum.ionicframework.com/t/ionic-firebase-angularfire2-user-roles-and-database/127309/4 "2018-04-09T13:53:19Z")

</div>

> [@benmcm1994](#):
>
> firebase.auth().currentUser.uid;

Why are you mixing idioms then?

---

<div class="post-metadata">

**Author:** ![benmcm1994](https://avatars.discourse-cdn.com/v4/letter/b/e9bcb4/32.png) [@benmcm1994](https://forum.ionicframework.com/u/benmcm1994)\
**Post date:** [April 9, 2018, 1:55pm UTC](https://forum.ionicframework.com/t/ionic-firebase-angularfire2-user-roles-and-database/127309/5 "2018-04-09T13:55:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [April 9, 2018, 1:56pm UTC](https://forum.ionicframework.com/t/ionic-firebase-angularfire2-user-roles-and-database/127309/6 "2018-04-09T13:56:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jaydz](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jaydz](https://forum.ionicframework.com/u/jaydz)\
**Post date:** [April 9, 2018, 3:34pm UTC](https://forum.ionicframework.com/t/ionic-firebase-angularfire2-user-roles-and-database/127309/7 "2018-04-09T15:34:38Z")

</div>

[https://javebratt.com/ionic-firebase-authentication/](https://javebratt.com/ionic-firebase-authentication/)

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)

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:41pm UTC](https://forum.ionicframework.com/t/ionic-firebase-angularfire2-user-roles-and-database/127309/8 "2021-07-19T21:41:16Z")

</div>


