Javascript 使用Firebase auth(Web)捕获电子邮件更新错误
我正在Firebase中更新用户的电子邮件,然后:Javascript 使用Firebase auth(Web)捕获电子邮件更新错误,javascript,firebase,firebase-authentication,Javascript,Firebase,Firebase Authentication,我正在Firebase中更新用户的电子邮件,然后: const user=firebase.auth().currentUser; const credential=firebase.auth.EmailAuthProvider.credential('my-email@test.com“,”我的密码“); user.reauthenticateWithCredential(凭证)重新验证 .then(user.updateMail('my-new-email@test.com')) .然后((
const user=firebase.auth().currentUser;
const credential=firebase.auth.EmailAuthProvider.credential('my-email@test.com“,”我的密码“);
user.reauthenticateWithCredential(凭证)重新验证
.then(user.updateMail('my-new-email@test.com'))
.然后(()=>{
console.log('ok');
})
.catch((错误)=>{
如果(error.code===“身份验证/密码错误”){
// ...
}else if(error.code==='auth/invalid email'){
// ...
}else if(error.code==='auth/email已在使用'){
// ...
}
});
它可以工作,但我无法捕获由user.updateEmail
部分引发的错误。由于某些原因,user.reauthenticateWithCredential
部分的错误是错误的。例如,如果我输入了错误的密码,我的catch((error)=>{}
块中的代码auth/error password
code出现错误,但是如果我输入了无效的电子邮件,我在控制台中只有以下消息:
Uncaught
L {code: "auth/invalid-email", message: "The email address is badly formatted."}
Nervermind我是个白痴:
.then(user.updateEmail('my-new-email@test.com'))
应该是
.then(() => user.updateEmail('my-new-email@test.com'))