Code Ratchet
Code Ratchet

Reputation: 6029

Retrieve ID of newly created user Firebase

I'm studying Angular2 and the latest version of Firebase I have the following Firebase set up in my project, which is used for creating a new user based of email and password:

signUpUser(user: User) {
  firebase.auth().createUserWithEmailAndPassword(user.email, user.password).catch(function (error) {
    console.log(error);
  });
}

The user is created successfully, but how do I go about retrieving the newly created user id? I've gone through the documentation and not one section explains how I can retrieve it after the user has been created? can someone shed some light into how you go about doing this?

Upvotes: 2

Views: 972

Answers (1)

Code Ratchet
Code Ratchet

Reputation: 6029

Managed to resolve this question my self, by adding an enhancement to the code specified in the original question:

signUpUser(user: User) {
   firebase.auth().createUserWithEmailAndPassword(user.email, user.password).then(function (user) {
   console.log('uid', user.uid)
 }).catch(function (error) {
   console.log(error);
 });
}

Upvotes: 3

Related Questions