blob: 020aedf564f84606220057e6384e8996224dac71 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
// 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;
|