forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.ts
More file actions
58 lines (50 loc) · 1.78 KB
/
Copy pathclient.ts
File metadata and controls
58 lines (50 loc) · 1.78 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
import { initializeApp, getApps, getApp, type FirebaseApp } from 'firebase/app';
import { getAuth, type Auth } from 'firebase/auth';
import { getFirestore, type Firestore } from 'firebase/firestore';
import { getFunctions, type Functions } from 'firebase/functions';
import { getStorage, type FirebaseStorage } from 'firebase/storage';
const firebaseConfig = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
};
// Lazy initialization via getter functions.
// Proxies break Firebase SDK's instanceof checks in doc()/getDoc()/onAuthStateChanged(),
// so we return real instances directly.
let _app: FirebaseApp | null = null;
let _auth: Auth | null = null;
let _db: Firestore | null = null;
let _functions: Functions | null = null;
let _storage: FirebaseStorage | null = null;
function getFirebaseApp(): FirebaseApp {
if (!_app) {
_app = !getApps().length ? initializeApp(firebaseConfig) : getApp();
}
return _app;
}
function getFirebaseAuth(): Auth {
if (!_auth) _auth = getAuth(getFirebaseApp());
return _auth;
}
function getFirebaseDb(): Firestore {
if (!_db) _db = getFirestore(getFirebaseApp());
return _db;
}
function getFirebaseFunctions(): Functions {
if (!_functions) _functions = getFunctions(getFirebaseApp());
return _functions;
}
function getFirebaseStorage(): FirebaseStorage {
if (!_storage) _storage = getStorage(getFirebaseApp());
return _storage;
}
export {
getFirebaseApp,
getFirebaseAuth,
getFirebaseDb,
getFirebaseFunctions,
getFirebaseStorage,
};