-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfirebaseadmin.ts
More file actions
26 lines (23 loc) · 748 Bytes
/
firebaseadmin.ts
File metadata and controls
26 lines (23 loc) · 748 Bytes
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
import admin from 'firebase-admin';
// Initialize Firebase Admin SDK
let serviceAccount;
try {
serviceAccount = JSON.parse(process.env.FIREBASE_ADMIN_SDK_KEY as string);
} catch (error) {
console.error('Error parsing FIREBASE_ADMIN_SDK_KEY:', error);
throw new Error('Invalid FIREBASE_ADMIN_SDK_KEY format');
}
if (!admin.apps.length) {
try {
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
projectId: serviceAccount.project_id,
});
console.log('✅ Firebase Admin initialized successfully');
} catch (error) {
console.error('Error initializing Firebase Admin:', error);
throw error;
}
}
export const adminAuth = admin.auth();
export const adminFirestore = admin.firestore();