-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase.ts
98 lines (87 loc) · 2.84 KB
/
firebase.ts
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// firebase.ts
import { initializeApp } from 'firebase/app';
import {
initializeAuth,
getAuth,
getReactNativePersistence,
} from '@firebase/auth';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { getFirestore } from 'firebase/firestore';
import { getStorage } from 'firebase/storage';
import { getFunctions, httpsCallable } from 'firebase/functions';
// Your Firebase configuration (from the Firebase console)
const firebaseConfig = {
apiKey: 'AIzaSyBGzk3lvP9pboBVpOERejYweH6Xk1dHB8k',
authDomain: 'goingoutapp-c90b1.firebaseapp.com',
projectId: 'goingoutapp-c90b1',
storageBucket: 'goingoutapp-c90b1.appspot.com',
messagingSenderId: '814136772684',
appId: '1:814136772684:web:287e5a3b413533b81b8ce9',
measurementId: 'G-XZSBDHERB0',
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Initialize Firebase services
let auth: ReturnType<typeof initializeAuth> | ReturnType<typeof getAuth>;
try {
auth = initializeAuth(app, {
persistence: getReactNativePersistence(AsyncStorage),
});
} catch (e: any) {
if (e.code === 'app/duplicate-app' || e.code === 'auth/already-initialized') {
auth = getAuth(app);
} else {
throw e;
}
}
const db = getFirestore(app);
const functions = getFunctions(app);
const storage = getStorage(app);
// const isAndroid = Platform.OS === 'android';
// const isIOS = Platform.OS === 'ios';
// let emulatorHost = 'localhost'; // Default for iOS Simulator
// let emulatorPort = 5001; // Default Functions emulator port
// if (isAndroid) {
// emulatorHost = '10.0.2.2'; // Android Emulator
// } else if (isIOS) {
// emulatorHost = 'localhost'; // iOS Simulator
// } else {
// // For physical devices, replace with your computer's IP
// emulatorHost = '192.168.4.160';
// }
// Connect to Functions emulator if in development
// if (__DEV__) {
// console.log('Connecting to Functions emulator:', emulatorHost, emulatorPort);
// connectFunctionsEmulator(functions, emulatorHost, emulatorPort);
// }
const deleteCrew = (crewId: string) => {
if (!auth.currentUser) {
throw new Error('User is not authenticated');
}
const deleteCrewCallable = httpsCallable(functions, 'deleteCrew');
return deleteCrewCallable({ crewId });
};
const pokeCrew = (crewId: string, date: string, userId: string) => {
if (!auth.currentUser) {
throw new Error('User is not authenticated');
}
const pokeCrewCallable = httpsCallable(functions, 'pokeCrew');
return pokeCrewCallable({ crewId, date, userId });
};
const deleteAccount = (targetUserId?: string) => {
if (!auth.currentUser) {
throw new Error('User is not authenticated');
}
const deleteAccountCallable = httpsCallable(functions, 'deleteAccount');
return deleteAccountCallable({ targetUserId });
};
export {
auth,
db,
functions,
storage,
deleteCrew,
pokeCrew,
deleteAccount,
firebaseConfig,
};