Silent
Silent

Reputation: 39

How to get the user id of the newly created user in firebase

This project is done using angular, I want to get the user id of the newly created user and set it to a variable so i can use it to identify the particular user using that id.

The Code:

submit()
  {
   this.Auth.createUserWithEmailAndPassword(this.form.Eemail, this.password).then( res => {
   this.user.addnotice(this.form);
   this.cancel();
   this.succesToast();
   }, err =>{
     this.failToast();
   })
  }

The above code creates the user but i want to get the id of the created user so how do i do that.

Upvotes: 0

Views: 103

Answers (1)

Renaud Tarnec
Renaud Tarnec

Reputation: 83191

As you can see in the doc, the createUserWithEmailAndPassword() method returns a Promise that resolves with a UserCredential.

You should therefore do as follows:

   this.Auth.createUserWithEmailAndPassword(this.form.Eemail, this.password)
      .then( res => {    // res is a UserCredential
          const userId = res.user.uid;
          // ...
   
       } ...

Upvotes: 1

Related Questions