My goal is to develop a function that retrieves information from my collection in order to log into my application.
With the help of this service, I am able to fetch all the necessary data:
getUsersLocal(): Observable<AdminUser[]> {
const booksRef = collection(this.firestore, 'admin-roles');
return collectionData(booksRef, { idField: 'id' }) as Observable<AdminUser[]>;
}
Now moving on to the implementation of the function:
login(): void{
if(this.loginForm?.valid){
let adminLogin: Admin = this.loginForm.value;
this.admin.getUsersLocal().subscribe({
next: response => {
if(this.email === adminEmail && this.password === adminPassword){
this.route.navigate(['/admin']);
}
} else {
window.alert("Usuário não encontrado")
}
})
}
}
I understand that there may be some errors in the structure, but I believe it's close to being correct.