Javascript 如何在firebase中获取新创建用户的用户id

Javascript 如何在firebase中获取新创建用户的用户id,javascript,firebase,firebase-authentication,Javascript,Firebase,Firebase Authentication,这个项目是使用angular完成的,我想获取新创建用户的用户id,并将其设置为一个变量,这样我就可以使用它来识别使用该id的特定用户 守则: submit() { this.Auth.createUserWithEmailAndPassword(this.form.Eemail, this.password).then( res => { this.user.addnotice(this.form); this.cancel(); this.succesToas

这个项目是使用angular完成的,我想获取新创建用户的用户id,并将其设置为一个变量,这样我就可以使用它来识别使用该id的特定用户

守则:

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

上面的代码创建了用户,但我想获取所创建用户的id,那么我该如何做。

正如您在文档中看到的,该方法返回一个承诺,该承诺通过一个

因此,你应采取以下行动:

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