Recently I upgraded to expo sdk 48, and with doing that firebase got updated to @9.18.0,
Everthing working fine except when i tried to add a new documnet using addDoc (all over my app, i use the addDoc in aproximately 15 screens)
(I also had a minor issue with getAuth due to asyncStorage incompability which i manage to resolve temporarily)
This is my firebase.js configuration:
import { initializeApp, getApps, getApp } from "firebase/app";
// import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";
import { getStorage } from "firebase/storage";
import { getDatabase } from "firebase/database";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { getReactNativePersistence, initializeAuth } from "firebase/auth/react-native";
const firebaseConfig = {}
let app;
if (getApps().length === 0) {
app = initializeApp(firebaseConfig);
} else {
app = getApp();
}
// const auth = getAuth(app);
const auth = initializeAuth(app, { persistence: getReactNativePersistence(AsyncStorage) }); // temporary solution instead of getAuth for the expo sdk 48 after removing asyncstroage deprecated version
const db = getFirestore(app);
const storage = getStorage(app);
const realtimeDB= getDatabase(app);
export { db, auth, storage, realtimeDB};
and here is a simplified example of one place that I’m using the addDoc function:
import { storage, db, auth } from "../firebase";
import { collection, doc, addDoc, serverTimestamp, setDoc } from "firebase/firestore";
const sendMessage = async (data) => {
payload = {
type: data.type,
userId: data.userId,
userName: data.userName,
body: data.body,
timestamp: serverTimestamp(),
};
const collRef = collection(db, "chats", data.chatId, "messages");
let messageId = "first_message";
try {
const docRes = await addDoc(collRef, payload);
messageId = docRes.id;
} catch (error) {
console.log("addDoc Error: ", error);
try {
await setDoc(doc(collRef, messageId), payload);
} catch (error) {
console.log("Failed of creating new message in Chats: ", error);
}
}
};
When running this code, the addDoc get skipped and setDoc is kick in and get exceuted,
this is the log i get in the console after calling sendMessage function:
LOG addDoc Error: [TypeError: undefined is not a function]
Please i really need any help with this.
thank you kind people.
I tried, of course downgrading expo sdk back to 47, and firebase to 9.17.0,
and nothing was changed, I also tried to remove node_moduls and reinstall them which did nothing.
I also tried asking my friend chatGPT, which have no clue LOL.