更新电子邮件时无法捕获已使用的身份验证/电子邮件

时间:2017-10-27 17:14:19

标签: angular typescript firebase firebase-authentication

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

我能够捕获错误的密码错误,但是当遇到auth/email-already-in-use错误时,它不起作用。

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

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;
      }
    })
  }

轮廓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 });
        });
      });
  };

1 个答案:

答案 0 :(得分:0)

由于新的电子邮件已被使用,似乎// Shape - superclass function Shape() { this.x = 0; this.y = 0; } // superclass method Shape.prototype.move = function(x, y) { this.x += x; this.y += y; console.info('Shape moved.'); }; // Rectangle - subclass function Rectangle() { Shape.call(this); // call super constructor. } // subclass extends superclass Rectangle.prototype = Object.create(Shape.prototype); Rectangle.prototype.constructor = Rectangle; var rect = new Rectangle(); console.log('Is rect an instance of Rectangle?', rect instanceof Rectangle); // true console.log('Is rect an instance of Shape?', rect instanceof Shape); // true rect.move(1, 1); // Outputs, 'Shape moved.' 正在抛出它,你可以在这里抓住:

updateEmail