我正在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."}
答案 0 :(得分:0)
Nervermind我是个白痴:
.then(user.updateEmail('my-new-email@test.com'))
应该是
.then(() => user.updateEmail('my-new-email@test.com'))