cbd*_*per 6 javascript async-await firebase firebase-authentication
正在处理 Firebase 身份验证的登录表单。
当我这样做时async await:
async function doLogin(email,password) {
setLoading(true);
try {
const userCredential = await firebase.auth().signInWithEmailAndPassword(email, password);
console.log(userCredential);
}
catch(err) {
console.log(err);
}
}
Run Code Online (Sandbox Code Playgroud)
当上面的代码引发登录错误时,我会记录两条重复的错误消息,其中之一是uncaught. 而这uncaught一位来自auth.esm.js:67
当我用一个做的时候.then().catch()
async function doLogin(email,password) {
setLoading(true);
firebase.auth().signInWithEmailAndPassword(email, password)
.then((user) => console.log(user))
.catch((err) => console.log(err));
}
Run Code Online (Sandbox Code Playgroud)
我只收到一条错误消息。我的代码中的一个,这是预期的行为。
问题
我在版本中做错了什么吗async await?难道不应该同样工作吗?为什么 Firebase 会抛出未捕获的错误?
我已经联系了 firebase 团队,这是他们的答案:
感谢 cbdeveloper 提供完整的可重现代码。我能够重现该问题,看起来这是我们这边的一个已知问题。根据我们的 GitHub 存储库报告的问题 #1881 ,目前唯一的选择是接受额外的控制台错误或避免在身份验证方法上使用 async/await,因为如果不对我们的 SDK 进行大量重写,这是无法完成的。请参阅我们的一位 Firebase 工程师的详细说明。截至目前,我们尚未找到有关何时修复的任何细节或时间表。您可以不时查看我们的发行说明或加入更新讨论。