Interface -- >
export interface User {
uid: string;
name: string;
bloq:boolean;
email: string;
photoURL: string;
address?: string;
admin?: boolean;
obs?: string;
createdAt: number;
updatedAt: number;
}
Ok, now we have the function to perform the login system
async loginUser(userEmail, userPsw) {
this.showSpinner = true;
await this.authService.login(userEmail, userPsw)
.then(res => {
if (res) {
localStorage.setItem('userUID', res.user.uid);
localStorage.setItem('userEmail', res.user.email);
this.authService.getUserProfile(res.user.uid)
.pipe(take(1))
.subscribe({
next: (res) => {
this.showSpinner = false;
let userRes = res.payload.data();
localStorage.setItem('userProfile', JSON.stringify(userRes));
if(userRes['bloq']===false){
this.router.navigateByUrl('/inicio');
}else{
Swal.fire({
icon: 'warning',
title: 'Oops...',
text: 'Acesso negado! Por favor, fale com os Administradores.'
});
return this.authService.logout();
}
}, error: (error) => this.showSpinner = false,
complete: () => this.showSpinner = false
});
} else {
this.showSpinner = false;
Swal.fire({
icon: 'warning',
title: 'Oops...',
text: 'Usuário não existe, ou dados incorretos.'
});
this.router.navigate(['/login']);
}
}).catch((err)=>{
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Informe os seus dados.'
});
// console.log('Opss... algo errado.');
this.router.navigate(['/login']);
});