1

I am new to Firestore and async functions. Below function is in angular service:

 async verifyCredentials(loginFormData:any)
  {
    const q = query(collection(db, "users"), where("mobile", "==", loginFormData["mobile"]), where("email", "==", loginFormData["email"]));
    const querySnapshot = await getDocs(q);
    //console.log("data is:", querySnapshot.docs[0].data());
    return querySnapshot.docs[0].data();
  }

I am calling above function to get data in a component:

 onSubmit() {
    
    this.submitted = true;
    if (this.loginForm.invalid) {
        return;
    }
    if(this.submitted)
    {
      console.log(this.userService.verifyCredentials(this.loginForm.value)); 
      //this.router.navigate(['/menu']);
    }
  
  }

Below is the console output:

Console

2
  • "returning doc.data() is not working here" What does that mean? Which line of the code you shared doesn't do what you expect it to do? Is there an error message? Commented Jan 1, 2022 at 17:43
  • Sorry for the incomplete information @FrankvanPuffelen . I have updated the question. Please have a look. Thanks! Commented Jan 2, 2022 at 3:21

1 Answer 1

2

It worked. I completely forget to use .then

onSubmit() { 
    this.submitted = true;
    if (this.loginForm.invalid) {
        return;
    }
    if(this.submitted)
    {
      this.userService.verifyCredentials(this.loginForm.value).then( data => 
      {
        console.log(data); 
      });
      //this.router.navigate(['/menu']);
    }
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.