Firebase auth().signInWithEmailAndPassword using try-catch async-await uncaught error

Viewed 1756

Working on a login form for Firebase auth.

When I do it with 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);
    }
  }

When the code above throws a login error, I get two duplicate error messages logged, and one of them is uncaught. And the uncaught one is from auth.esm.js:67

enter image description here

When I do it with a .then().catch()

async function doLogin(email,password) {
  setLoading(true);
  firebase.auth().signInWithEmailAndPassword(email, password)
  .then((user) => console.log(user))
  .catch((err) => console.log(err));
}

I get only one error message. The one from my code, which is the intended behavior.

enter image description here

QUESTION

Am I doing something wrong in the async await version? Shouldn't it be working just the same? Why is Firebase throwing the uncaught error?

1 Answers

I've contacted the firebase team and this was their answer:

Thanks for providing a complete reproducible code, cbdeveloper. I was able to reproduce the issue, and it looks like this is a known issue on our end. Based on the reported issue #1881 from our GitHub repository, the only options for now are to either accept the extra console errors or avoid using async/await on auth methods as this can't be done without a large rewrite on our SDK. See detailed explanation here from one of our Firebase engineers. As of now, we are yet to find out any details or timelines as to when it will be fixed. You can check out our release notes from time to time or join the discussion for updates.

Related