Firebase authentication still throws error in console, even if I catch it

Viewed 202

I'm trying to build an app using angular and firebase authentication.

auth.service.ts

async loginWithEmailAndPassword(email: string, password: string) {
  try {
    await this.auth.signInWithEmailAndPassword(email, password);
  } catch(error) {
    throw error;
  }    
}

login-page.component

async loginWithEmailAndPassword() {
  if (this.form.status !== 'INVALID') {
    try {
      await this.authService.loginWithEmailAndPassword(this.email?.value, this.password?.value)
    } catch(error) {
      console.log('Hello, this is my custom error');
    }
  }
}

But in the console firebase still throws the error: Console

Is this the intended behaviour? I thought that try...catching would prevent this.

I even tried removing async await syntax but nothing changed.

1 Answers

I use following code to catch error in component

login-page.component

   this.auth.SignIn(this.email, this.password).then(function(result){
 console.log(result);
}).catch(function(e){
console.log(e);
});

Auth.service

   return this.afAuth.auth.signInWithEmailAndPassword(email, password);
Related