Skip to content

AngularFire not catching error message for signInWithEmailAndPassword #3405

@tc-dev-git

Description

@tc-dev-git

My stackoverflow: https://stackoverflow.com/questions/76622221/angularfire-not-catching-error-message-for-signinwithemailandpassword

Tech stack:

Having trouble catching the error message and stopping it appearing as red in the console log. I've written catch in the service but doesn't seem to stop it,

App Module:

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    AngularFireModule.initializeApp(environment.firebase),
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
  ],
  providers: [
    AuthenticationService.
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Login Component:

login(): void {
    if (this.form.valid) {
      const { email, password } = this.form.value;
      try {
        this.authenticationService.login(email, password)
          .then(() => {

          })
          .catch(() => {
            console.log('Error caught 1');
          })
      }
      catch {
        console.log('Error caught 2');
      }
    }
  }

Authentication Service:

import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/compat/auth';
import { Router } from '@angular/router';

@Injectable({
  providedIn: 'root'
})
export class AuthenticationService {
  constructor(private angularFireAuth: AngularFireAuth, private router: Router) { }

login(email: string, password: string): any {
    try {
      return this.angularFireAuth
        .signInWithEmailAndPassword(email, password)
        .then(() => this.router.navigate(['basics']))
        .catch((error: any) => {
          console.warn(error);
        });
    }
    catch {
      console.log('Error caught 3');
    }
  }

Error message I want to catch and prevent showing in console:

enter image description here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions