Download workspace/src/lib/firebase-admin.ts from looda3131/looood: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/looda3131/looood/resolve/main/workspace/src/lib/firebase-admin.ts
- Command line
-
hf download hf://spaces/looda3131/looood/workspace/src/lib/firebase-admin.ts
-
curl -L -o firebase-admin.ts https://huggingface.co/spaces/looda3131/looood/resolve/main/workspace/src/lib/firebase-admin.ts
1.03 kB
| 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 }; | |