javascript - 使用 Firebase auth (Web) 捕获电子邮件更新错误
问题描述
我正在通过重新验证用户身份然后更新用户来更新用户在 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
部分的错误是caugth。例如,如果我输入了错误的密码auth/wrong-password
,我的块中的代码代码就会出错catch((error) => {}
,但是如果我输入了无效的电子邮件,我只会在控制台中看到以下消息:
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'))
推荐阅读
- pandas - PYODBC 未关闭与 Access 数据库的连接
- html - 将项目添加到网络应用程序的 Firebase 链接不起作用
- c++ - 在我的 cpp 程序中保留/删除冗余 cout 会改变我的答案
- python - 这个 Python elasticsearch SSL 错误是否意味着传输完整性受到损害:“当使用 `ssl_context` 时,所有其他与 SSL 相关的 kwargs 都会被忽略”?
- flutter - Flutter widget.snapshot.data vs snapshot.data
- linux - 期望 SFTP 的脚本在 bash 中不起作用
- javascript - FCC Drum Machine - 通过测试但 keydown 事件没有为我触发
- apache-spark - Spark 从 VSCode 连接但不从 Jupyter 连接
- angular - 当我在 Angular 中有一个局部变量时,如何测试一个函数?
- python - Python TypeError:切片索引必须是整数或无或具有 __index__ 方法