使用Firebase身份验证(Web)捕获电子邮件更新错误

时间:2018-05-02 20:53:09

标签: javascript firebase firebase-authentication

我正在re-authenticating him然后updating the user更新Firebase中用户的电子邮件:

const user = firebase.auth().currentUser;
const credential = firebase.auth.EmailAuthProvider.credential('my-email@test.com', 'my-password');

user.reauthenticateWithCredential(credential)
    .then(user.updateEmail('my-new-email@test.com'))
    .then(() => {
      console.log('ok');
    })
    .catch((error) => {
      if (error.code === 'auth/wrong-password') {
        // ...
      } else if (error.code === 'auth/invalid-email') {
        // ...
      } else if (error.code === 'auth/email-already-in-use') {
        // ...
      }
    });

它有效,但我无法捕捉到user.updateEmail部分引发的错误。由于某些原因,user.reauthenticateWithCredential部分的错误是谨慎的。例如,如果我输入了错误的密码,我的auth/wrong-password块中的代码catch((error) => {}代码出错,但如果我输入的邮件无效,我只在控制台中显示此消息:

Uncaught 
L {code: "auth/invalid-email", message: "The email address is badly formatted."}

1 个答案:

答案 0 :(得分:0)

Nervermind我是个白痴:

.then(user.updateEmail('my-new-email@test.com'))

应该是

.then(() => user.updateEmail('my-new-email@test.com'))
相关问题