Search code examples
javascriptfirebasefirebase-authenticationangularfire2

How to get the uid of a registered user with ionic and firebase


I'm trying to register a user with firebase, once the user is registered, I would like to add them to the firestore database but I can't access the uid of the user that just registered.

registerUser(name: string, email: string, password: string): Promise<any> {
return this.afAuth.auth.createUserWithEmailAndPassword(email, password).then((newUser:any) => {
    console.log(newUser.uid)
});
}

newUser.uid is undefined, how do I access this value?

Thanks


Solution

  • according to the documentation here - https://firebase.google.com/docs/reference/js/firebase.auth.Auth#createUserWithEmailAndPassword

    the function returns "returns firebase.Promise containing non-null firebase.auth.UserCredential"

    console.log(newUser.user.uid)