File size: 1,029 Bytes
cc276cc | 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 |
import { initializeApp, getApps, App, cert, ServiceAccount } from 'firebase-admin/app';
import { getDatabase } from 'firebase-admin/database';
import { getFirestore } from 'firebase-admin/firestore';
import { getMessaging } from 'firebase-admin/messaging';
import serviceAccount from '@/../service-account.json';
// Correctly type the service account object for the cert function
const serviceAccountInfo: ServiceAccount = {
projectId: serviceAccount.project_id,
privateKey: serviceAccount.private_key,
clientEmail: serviceAccount.client_email,
};
const firebaseAdminConfig = {
credential: cert(serviceAccountInfo),
databaseURL: process.env.NEXT_PUBLIC_FIREBASE_DATABASE_URL,
};
let adminApp: App;
if (!getApps().length) {
adminApp = initializeApp(firebaseAdminConfig);
} else {
adminApp = getApps()[0];
}
const adminDb = getDatabase(adminApp);
const adminFirestore = getFirestore(adminApp);
const adminMessaging = getMessaging(adminApp);
export { adminApp, adminDb, adminFirestore, adminMessaging };
|