added login error msg
This commit is contained in:
parent
f0712fa0c3
commit
24cf13f61e
3 changed files with 9 additions and 6 deletions
|
|
@ -32,6 +32,8 @@
|
||||||
<div class="error-msg">
|
<div class="error-msg">
|
||||||
@if (!mail.valid && mail.touched) {
|
@if (!mail.valid && mail.touched) {
|
||||||
<p>You must enter a mail.</p>
|
<p>You must enter a mail.</p>
|
||||||
|
} @if (loginSerivce.errorCode == 'auth/invalid-email') {
|
||||||
|
<p>This email address does not exist.</p>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
|
|
@ -52,6 +54,8 @@
|
||||||
<div class="error-msg">
|
<div class="error-msg">
|
||||||
@if (!password.valid && password.touched) {
|
@if (!password.valid && password.touched) {
|
||||||
<p>You must enter a password.</p>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ export class LoginComponent {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private firebaseService: FirebaseService,
|
private firebaseService: FirebaseService,
|
||||||
private loginSerivce: LoginService,
|
public loginSerivce: LoginService,
|
||||||
public sharedService: SharedService,
|
public sharedService: SharedService,
|
||||||
private router: Router
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
import { Injectable, inject } from '@angular/core';
|
import { Injectable, inject } from '@angular/core';
|
||||||
import { getAuth, signInWithEmailAndPassword } from 'firebase/auth';
|
import { getAuth, signInWithEmailAndPassword } from 'firebase/auth';
|
||||||
import { FirebaseService } from './firebase.service';
|
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';
|
import { SharedService } from './shared.service';
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class LoginService {
|
export class LoginService {
|
||||||
firestore: Firestore = inject(Firestore);
|
firestore: Firestore = inject(Firestore);
|
||||||
|
errorCode: string = '';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private firebaseService: FirebaseService,
|
private firebaseService: FirebaseService,
|
||||||
|
|
@ -15,9 +16,7 @@ export class LoginService {
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
login(loginData: { mail: string; password: string }) {
|
login(loginData: { mail: string; password: string }) {
|
||||||
const auth = getAuth();
|
signInWithEmailAndPassword(getAuth(), loginData.mail, loginData.password)
|
||||||
|
|
||||||
signInWithEmailAndPassword(auth, loginData.mail, loginData.password)
|
|
||||||
.then((userCredential) => {
|
.then((userCredential) => {
|
||||||
const user = userCredential.user;
|
const user = userCredential.user;
|
||||||
if (this.firebaseService.checkUserUID(user.uid).length > 0) {
|
if (this.firebaseService.checkUserUID(user.uid).length > 0) {
|
||||||
|
|
@ -32,7 +31,7 @@ export class LoginService {
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
alert('Invalid email or password! Please try again.');
|
this.errorCode = error.code;
|
||||||
this.sharedService.isBtnDisabled = false;
|
this.sharedService.isBtnDisabled = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue