-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirebaseConfig.js
More file actions
39 lines (32 loc) · 1.43 KB
/
Copy pathfirebaseConfig.js
File metadata and controls
39 lines (32 loc) · 1.43 KB
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
38
39
// firebaseConfig.js
// Complete Firebase Configuration for Zero Trap
import { initializeApp, getApp, getApps } from 'firebase/app';
import { getAuth, initializeAuth, getReactNativePersistence } from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';
import { getStorage } from 'firebase/storage';
import AsyncStorage from '@react-native-async-storage/async-storage';
// Supply Firebase values through EXPO_PUBLIC_* environment variables.
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 || ''
};
// Single Firebase app instance (avoids "already exists" on Fast Refresh)
const app = getApps().length === 0 ? initializeApp(firebaseConfig) : getApp();
// Initialize Auth with AsyncStorage persistence (getAuth fallback avoids crash on Fast Refresh)
let auth;
try {
auth = initializeAuth(app, {
persistence: getReactNativePersistence(AsyncStorage)
});
} catch (e) {
auth = getAuth(app);
}
// Initialize Firestore
const db = getFirestore(app);
// Initialize Storage (for future use when upgraded to Blaze)
const storage = getStorage(app);
export { app, auth, db, storage };