Auth related functions work, but with firestore I cant get anything to happen. No errors no successes returned by try catch. I have created the firestore in the firebase console, The created accounts show successfully from auth, but I just can't get anything to happen in firestore database
export const myApp = initializeApp(firebaseConfig);
// firebase.firestore().settings({ experimentalForceLongPolling: true });
export const db = getFirestore(myApp);
export const auth = getAuth(myApp);
export const logout = signOut;
// const dbInstance = collection(database, 'users');
export const addUser = async () => {
try {
console.log("Firing add function");
const docRef = await addDoc(collection(db, "users"), {
first: "Ada",
last: "Lovelace",
born: 1815,
});
console.log("Document written with ID: ", docRef);
// console.log("Document written with ID: ", docRef.id);
} catch (e) {
console.error("Error adding document: ", e);
}
};
I only get "Firing add function" then nothing. No errors or anything.
If i remove the await and then console docRef instead of docRef.id, then I get "Document written with ID: " and a Promise in a pending state.
Edit: I tried to use getDocs
export const getUsers = async () => {
console.log("Getting users")
const querySnapshot = await getDocs(collection(db, "users"));
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data());
});
console.log("After get users")
};
@firebase/firestore: Firestore (9.6.11): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=not-found]: The project undefined does not exist or it does not contain an active Cloud Datastore or Cloud Firestore database. Please visit http://console.cloud.google.com to create a project or https://console.cloud.google.com/datastore/setup?project=undefined to add a Cloud Datastore or Cloud Firestore database. Note that Cloud Datastore or Cloud Firestore always have an associated App Engine app and this app must not be disabled. This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
But I go to my console and my Firestore is here and has one collection and one document that i made here from console
Embarrassing, I console logged my firebaseConfig object and realized my FIREBASE_PROJECT_ID was undefined, I looked into my env file and realized it was not capitalized, so my firebase requests just couldn't find my firestore.
I would have not thought to look here since my auth related functions were working perfectly, but I guess auth related functions didn't need project ID to work so I never caught the misspell