I'm trying to get a document from Firebase Firestore but every time I try getting it I get an error that my "onHomeLoad" function is not declared and if I put it in the console I then get either that doc() or getDoc() aren't declared. I tried everything I've found online but nothing worked.
My code:
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.0.0/firebase-app.js";
import { getFirestore , getDoc , doc } from "https://www.gstatic.com/firebasejs/9.0.0/firebase-firestore.js";
const firebaseApp = initializeApp({
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: ""
});
const db = getFirestore(firebaseApp);
function onHomeLoad() {
let siteSettingsHome = doc(db, 'siteSettings/home');
getDocument(siteSettingsHome);
}
async function getDocument(docLocation) {
let documentSnapshot = await getDoc(docLocation);
if( homeSettingSnapshot.exists() ){
let documentData = documentSnapshot.data();
console.log(`Doc data: ${JSON.stringify( documentData )}`);
return documentData;
}
}
I've removed the stuff inside the initializeApp object here but it's filled correctly in my js document.