if somebody is facing the same issue with firabase emulator for an expo app running on ios simulator, I got it fixed with below steps.
add host to the firebase.json in firebase side
"emulators": {
"functions": {
"port": 5001,
"host": "0.0.0.0"
},
"firestore": {
"port": 8080,
"host": "0.0.0.0"
},
"ui": {
"enabled": true
},
"singleProjectMode": true,
"export": {
"path": "emulator-data"
}
}
and then in expo side, where you initialize firebase apps
import Constants from "expo-constants";
import { getApps, initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { connectFirestoreEmulator, getFirestore } from "firebase/firestore";
import { connectFunctionsEmulator, getFunctions } from "firebase/functions";
const firebaseConfig = {
apiKey: process.env.EXPO_PUBLIC_FIREBASE_API_KEY,
authDomain: process.env.EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN,
projectId: process.env.EXPO_PUBLIC_FIREBASE_PROJECT_ID,
storageBucket: process.env.EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.EXPO_PUBLIC_FIREBASE_APP_ID,
};
const app = getApps().length ? getApps()[0] : initializeApp(firebaseConfig);
const origin = Constants.expoConfig?.hostUri?.split(':')[0] || 'localhost';
export const db = getFirestore(app);
export const auth = getAuth(app);
export const functions = getFunctions(app, "asia-south1");
if (__DEV__ && process.env.EXPO_PUBLIC_USE_EMULATORS === "1") {
console.log(`🔌 Using local Firebase emulators... ${origin}`);
connectFunctionsEmulator(functions, origin, 5001);
connectFirestoreEmulator(db, origin, 8080);
}
export default app;