-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
My stackoverflow: https://stackoverflow.com/questions/76622221/angularfire-not-catching-error-message-for-signinwithemailandpassword
Tech stack:
- Firebase (firebase: "9.6.3",).
- AngularFire (@angular/fire": "^7.6.1").
- Angular v16.
- Npm: https://www.npmjs.com/package/@angular/fire
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:
Metadata
Metadata
Assignees
Labels
No labels
