Repository navigation
Expand file tree
/
Copy pathfirebaseConfig.ts
More file actions
63 lines (58 loc) · 1.8 KB
/
Copy pathfirebaseConfig.ts
File metadata and controls
63 lines (58 loc) · 1.8 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
import {
getReactNativePersistence,
getAuth,
initializeAuth,
inMemoryPersistence,
Auth,
} from 'firebase/auth';
import { getStorage } from 'firebase/storage';
import { getDatabase } from 'firebase/database';
import { Platform } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
/**
* The configuration object for the Firebase app.
*/
export 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 requiredKeys = ['apiKey', 'authDomain', 'projectId', 'storageBucket', 'messagingSenderId', 'appId'] as const;
const missing = requiredKeys.filter(k => !firebaseConfig[k]);
if (missing.length > 0) {
console.error(`Firebase config missing: ${missing.join(', ')}. Check EXPO_PUBLIC_FIREBASE_* env vars.`);
}
/**
* The initialized Firebase app instance.
*/
export const app = initializeApp(firebaseConfig);
let auth: Auth;
if (Platform.OS === 'web') {
auth = getAuth(app);
auth.setPersistence(inMemoryPersistence);
} else {
auth = initializeAuth(app, {
persistence: getReactNativePersistence(AsyncStorage),
});
}
/**
* The Firebase Authentication instance.
*/
export { auth };
/**
* The Firestore database instance.
*/
export const db = getFirestore(app);
/**
* The Firebase Storage instance.
*/
export const storage = getStorage(app);
/**
* The Firebase Realtime Database instance.
*/
export const realtime = getDatabase(app);