Javascript Firebase auth()。使用try-catch async Wait uncaught错误使用Email和Password进行登录
正在处理Firebase auth的登录表单 当我使用Javascript Firebase auth()。使用try-catch async Wait uncaught错误使用Email和Password进行登录,javascript,firebase,async-await,firebase-authentication,Javascript,Firebase,Async Await,Firebase Authentication,正在处理Firebase auth的登录表单 当我使用async wait: async function doLogin(email,password) { setLoading(true); try { const userCredential = await firebase.auth().signInWithEmailAndPassword(email, password); console.log(userCredential); }
async wait:
async function doLogin(email,password) {
setLoading(true);
try {
const userCredential = await firebase.auth().signInWithEmailAndPassword(email, password);
console.log(userCredential);
}
catch(err) {
console.log(err);
}
}
当上面的代码抛出登录错误时,我会记录两条重复的错误消息,其中一条是uncaught
。而uncaught
一个来自auth.esm.js:67
当我使用.then().catch()
我只收到一条错误消息。我的代码中的一个,这是预期的行为
问题
我在
异步等待
版本中是否做错了什么?它不应该同样工作吗?为什么Firebase会抛出未捕获错误?我已经联系了Firebase团队,他们的答案是:
感谢您提供完整的可复制代码,cbdeveloper。
我能够重现这个问题,看起来这是我们这边的一个已知问题。
根据我们GitHub存储库的报告,目前唯一的选择是接受额外的控制台错误或避免在auth方法上使用async/await,因为如果不在我们的SDK上进行大量重写,这是无法完成的。请参阅我们的Firebase工程师的详细解释。到目前为止,我们还没有找到任何细节或时间表,以确定何时将被固定。您可以不时查看我们的发行说明,或加入更新
async function doLogin(email,password) {
setLoading(true);
firebase.auth().signInWithEmailAndPassword(email, password)
.then((user) => console.log(user))
.catch((err) => console.log(err));
}