Currently, I am utilizing Angular 11 in conjunction with Firestore. Within my code, I am fetching data using the subscribe method from an API service. Subsequently, I am employing a for loop to extract object values in order to verify if a value within a collection exists. The issue I am encountering is that even when the value does exist, it enters the conditional "if" statement block as intended; however, it also proceeds into the "else" statement. I attempted incorporating a break statement within the "if" block but unfortunately it did not yield the desired outcome.
Here is a snippet of the code:
register() {
this.api.getLoginInfo().pipe(take(1)).subscribe(res => {
for (let i = 0; i < Object.keys(res).length; i++) {
this.checkem = res[i].payload.doc.data()['email'];
if (this.registerForm.value.email !== this.checkem) {
alert("Registered Successfully");
this.router.navigate(['/first']);
localStorage.setItem("isLogged", "true");
} else {
console.log("Already Registered");
alert("Already Registered!");
}
}
});
}
Furthermore, here is the related API Service method:
getLoginInfo() {
return this.firestore.collection("users").snapshotChanges();}