// src/shared/lib/firebase/config.ts import { initializeApp, getApps, getApp } from 'firebase/app'; import { initializeAuth, getReactNativePersistence, } from 'firebase/auth'; import AsyncStorage from '@react-native-async-storage/async-storage'; import { getFirestore } from 'firebase/firestore'; function getRequiredEnv(name: string): string { const value = process.env[name]; if (!value) { throw new Error(`Missing required environment variable: ${name}`); } return value; } const firebaseConfig = { apiKey: getRequiredEnv('EXPO_PUBLIC_FIREBASE_API_KEY'), authDomain: getRequiredEnv('EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN'), projectId: getRequiredEnv('EXPO_PUBLIC_FIREBASE_PROJECT_ID'), storageBucket: getRequiredEnv('EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET'), messagingSenderId: getRequiredEnv('EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID'), appId: getRequiredEnv('EXPO_PUBLIC_FIREBASE_APP_ID'), }; const app = getApps().length ? getApp() : initializeApp(firebaseConfig); export const auth = initializeAuth(app, { persistence: getReactNativePersistence(AsyncStorage), }); export const db = getFirestore(app); export default app;