Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

510
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda