diff --git a/src/app/components/login/login.component.html b/src/app/components/login/login.component.html index 4b88553..3a890b8 100644 --- a/src/app/components/login/login.component.html +++ b/src/app/components/login/login.component.html @@ -32,6 +32,8 @@
@if (!mail.valid && mail.touched) {

You must enter a mail.

+ } @if (loginSerivce.errorCode == 'auth/invalid-email') { +

This email address does not exist.

}
@if (!password.valid && password.touched) {

You must enter a password.

+ } @if (loginSerivce.errorCode == 'auth/invalid-credential') { +

The password does not match the email address

} diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts index 69cf239..186d213 100644 --- a/src/app/components/login/login.component.ts +++ b/src/app/components/login/login.component.ts @@ -22,7 +22,7 @@ export class LoginComponent { constructor( private firebaseService: FirebaseService, - private loginSerivce: LoginService, + public loginSerivce: LoginService, public sharedService: SharedService, private router: Router ) {} diff --git a/src/app/services/login.service.ts b/src/app/services/login.service.ts index ccbf0df..a303755 100644 --- a/src/app/services/login.service.ts +++ b/src/app/services/login.service.ts @@ -1,13 +1,14 @@ import { Injectable, inject } from '@angular/core'; import { getAuth, signInWithEmailAndPassword } from 'firebase/auth'; import { FirebaseService } from './firebase.service'; -import { Firestore, collection, query, where } from '@angular/fire/firestore'; +import { Firestore } from '@angular/fire/firestore'; import { SharedService } from './shared.service'; @Injectable({ providedIn: 'root', }) export class LoginService { firestore: Firestore = inject(Firestore); + errorCode: string = ''; constructor( private firebaseService: FirebaseService, @@ -15,9 +16,7 @@ export class LoginService { ) {} login(loginData: { mail: string; password: string }) { - const auth = getAuth(); - - signInWithEmailAndPassword(auth, loginData.mail, loginData.password) + signInWithEmailAndPassword(getAuth(), loginData.mail, loginData.password) .then((userCredential) => { const user = userCredential.user; if (this.firebaseService.checkUserUID(user.uid).length > 0) { @@ -32,7 +31,7 @@ export class LoginService { }) .catch((error) => { console.error(error); - alert('Invalid email or password! Please try again.'); + this.errorCode = error.code; this.sharedService.isBtnDisabled = false; }); }