added login error msg

This commit is contained in:
Chneemann 2024-04-28 15:44:02 +02:00
parent f0712fa0c3
commit 24cf13f61e
3 changed files with 9 additions and 6 deletions

View file

@ -32,6 +32,8 @@
<div class="error-msg">
@if (!mail.valid && mail.touched) {
<p>You must enter a mail.</p>
} @if (loginSerivce.errorCode == 'auth/invalid-email') {
<p>This email address does not exist.</p>
}
</div>
<input
@ -52,6 +54,8 @@
<div class="error-msg">
@if (!password.valid && password.touched) {
<p>You must enter a password.</p>
} @if (loginSerivce.errorCode == 'auth/invalid-credential') {
<p>The password does not match the email address</p>
}
</div>
</div>

View file

@ -22,7 +22,7 @@ export class LoginComponent {
constructor(
private firebaseService: FirebaseService,
private loginSerivce: LoginService,
public loginSerivce: LoginService,
public sharedService: SharedService,
private router: Router
) {}

View file

@ -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;
});
}