Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

506
Views
is there a way to get around using 'await' here?

I am trying to get all the documents in a subcollection by following the firebase documentation, however the error 'await is an reserved identifier' appears.

This is my code currently and I do not see where 'async' could be used with await and the documentation does not indicate that it would be used.

getAuth().onAuthStateChanged((user) => {
  if (user) {
    const app = initializeApp(firebaseConfig);
    const db = getFirestore(app);

    //reference to the subcollection of subjects in the user's document
    const subjectRef = collection(db, "users", auth.currentUser.uid, "subjects");

    const querySnapshot = await getDocs(subjectRef);

    querySnapshot.forEach((doc) => {
      console.log(doc.id, "=>", doc.data());
    });
  }
});

I have tried getting all the documents with db.collection.('users').document(auth.currentUser.uid).collection('subjects').get() where db = getFirestore(app), however this does not work as the error 'db.collection is not a function' appears and any soloutions I have found to it are not relevant as db is refering firestore not the real time database.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to make the callback async:

getAuth().onAuthStateChanged(async (user) => {
  if (user) {
    const app = initializeApp(firebaseConfig);
    const db = getFirestore(app);

    //reference to the subcollection of subjects in the user's document
    const subjectRef = collection(db, "users", auth.currentUser.uid, "subjects");

    const querySnapshot = await getDocs(subjectRef);

    querySnapshot.forEach((doc) => {
      console.log(doc.id, "=>", doc.data());
    });
  }
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!