This question is similar but didn't help.
The goal is to use async/await with Firebase Cloud Firestore queries instead of the then/catch Promise code from the Firebase documentation.
However, the function below rejects successfully in the negative case, but returns Promise { <pending> }
instead of the Cloud Firestore doc.
async getUser(emailAddress) {
// Return null if @emailAddress blank.
if (!emailAddress) {
return null;
}
// Assume @db points to a Cloud Firestore database. Query only returns one doc.
let query = db.collection('users').where('emailAddress', '==', emailAddress);
try {
let querySnapshot = await query.get();
querySnapshot.forEach(function(doc) {
return doc.data();
});
} catch(e) {
console.log('Error getting user: ', e);
}
}