Firestore: Uncaught SyntaxError: Unexpected reserved word

Sandren Troy Milante

I'm currently trying to upgrade my firebase code from version 8 to 9. However, I've encountered this error when I'm trying to get data from the database. It seems that await is causing the problem and I'm still pretty new in async.

function checkDatabaseData() {
    const uid = localStorage.getItem("uid");
    const docRef = doc(db, "userAdminCreds", uid);
    const docSnap = await getDoc(docRef);
    if (docSnap.exists()) {
      console.log("Document Data:", docSnap.data());
      return true;
    } else {
      console.log("No data");
      return false;
    }
  }

checkDatabaseData();

The HTML script tag

<script type="module" defer src="js/firebase-firestore-dashboard.js"></script>

This is just the same from the firebase guide: https://firebase.google.com/docs/firestore/query-data/get-data?authuser=0#web-version-9_1

Mises

To be able to use await word you need to have async word before function word.

async function checkDatabaseData() {
    // ...
    const docSnap = await getDoc(docRef);
    // ...
  }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related