Login Error

onLogin(): void {
  if (this.loginForm) {
    const email = this.loginForm.get('formEmail')?.value;
    const password = this.loginForm.get('formPassword')?.value;
    this.auth
      .signInWithEmailAndPassword(email as string, password as string)
      .then(() => this.router.navigate(['/']))
      .catch((error) => {
        console.error('Login error:', error);
        switch (error.code) {
          case 'auth/invalid-email':
          case 'auth/user-not-found':
          case 'auth/wrong-password':
            this.errorMessage = 'Hibás email cím vagy jelszó.';
            break;
          default:
            this.errorMessage = 'Username or password is incorrect.';
        }
      });
  }
}
Was this page helpful?