Spaces:
Configuration error
Configuration error
| const admin = require('firebase-admin'); | |
| const dotenv = require('dotenv'); | |
| dotenv.config(); | |
| let serviceAccount; | |
| try { | |
| // Try loading from file (local dev) | |
| serviceAccount = require('./serviceAccountKey.json'); | |
| } catch (e) { | |
| // Try loading from env var (production/HF) | |
| if (process.env.FIREBASE_SERVICE_ACCOUNT) { | |
| serviceAccount = JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT); | |
| } | |
| } | |
| if (!serviceAccount) { | |
| console.warn("WARNING: No service account found. Set FIREBASE_SERVICE_ACCOUNT env var or provide serviceAccountKey.json"); | |
| } else { | |
| admin.initializeApp({ | |
| credential: admin.credential.cert(serviceAccount) | |
| }); | |
| } | |
| const db = admin.firestore(); | |
| module.exports = { db }; | |