更新电子邮件时,无法捕获已使用的验证/电子邮件 [英] Cannot catch auth/email-already-in-use when Updating Email

查看:148
本文介绍了更新电子邮件时,无法捕获已使用的验证/电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了更新用户电子邮件的功能问题。该功能有三个主要的东西。首先,它将电子邮件更改为Firebase身份验证,然后更新数据库中的电子邮件,最后发送电子邮件验证。



我能够抓住不正确的密码错误,但是当涉及 auth / email-already-in-use 错误时,它不起作用。



问题是,我正在更新数据库中的电子邮件并发送验证电子邮件,但未更新Firebase身份验证中的电子邮件。



组件。 (更新!!)

  updateEmail(emailForm:NgForm){
let newEmail = emailForm.value.newEmail;
让密码= emailForm.value.password;
this.profileProvider.updateEmail(newEmail,password)
.then(value => {
this.showEditEmail =!this.showEditEmail;
this.authService.emailVerification()
.then(value => {
this.snackBar.open('Su correo ha sido modificado conéxito。Hemos envio de un enlace deverificacióna su nuevadirecciónde correoelectrónico'); $ b $ (b)}
.catch(error => {
console.log(`Chao $ {error.message}`)
})
})
。 catch(error => {
if(error){
console.log(`Hola $ {error.message}`);
this.emailPasswordError = error.message;
} else {
this.emailPasswordError = null;
}
})
}

profile-provider.service.ts

  updateEmail(newEmail:string,password:string) :firebase.Promise< any> {
const credential = firebase.auth.EmailAuthProvider $ b $ .credential(this.currentUser.email,password);
return this.currentUser.reauthenticateWithCredential(credential)
.then(user => {
this.currentUser.updateEmail(newEmail).then(user => {
this .userProfile.update({email:newEmail});
});
});
};


解决方案

/ code>正在抛出,因为已经使用了新的邮件,你可以在这里找到:

  this.currentUser .updateEmail(newEmail).then(user => {
this.userProfile.update({email:newEmail});
},error => {console.log(error);}) ;


I'm having a problem with the function to update the user email. The function does three main things. First, it changes the email to the Firebase Auth, then it updates the email in the database, and last it sends the email verification.

I'm able to catch the incorrect password error, but when it comes to auth/email-already-in-use error, it doesn't work.

The problem is that I'm updating the email in the database and sending the verification email, but it's not updating the email in Firebase Auth.

component.ts (UPDATED!!)

  updateEmail(emailForm: NgForm){
    let newEmail = emailForm.value.newEmail;
    let password = emailForm.value.password;
    this.profileProvider.updateEmail(newEmail, password)
    .then(value => {
      this.showEditEmail = !this.showEditEmail;
      this.authService.emailVerification()
      .then(value => {
        this.snackBar.open('Su correo ha sido modificado con éxito. Hemos enviado un enlace de verificación a su nueva dirección de correo electrónico');
      })
      .catch(error => {
        console.log(`Chao ${error.message}`)
      })
    })
    .catch(error => {
      if (error) {
        console.log(`Hola ${error.message}`);
      this.emailPasswordError = error.message;
      } else {
        this.emailPasswordError = null;
      }
    })
  }

profile-provider.service.ts

updateEmail(newEmail: string, password: string): firebase.Promise<any> {
    const credential =  firebase.auth.EmailAuthProvider
      .credential(this.currentUser.email, password);
    return this.currentUser.reauthenticateWithCredential(credential)
      .then( user => {
        this.currentUser.updateEmail(newEmail).then( user => {
          this.userProfile.update({ email: newEmail });
        });
      });
  };

解决方案

It seems like updateEmail is throwing it due to the new email already being used, you can catch here:

this.currentUser.updateEmail(newEmail).then(user => { 
  this.userProfile.update({ email: newEmail });
}, error => {console.log(error);});

这篇关于更新电子邮件时,无法捕获已使用的验证/电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆