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) {
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.