File size: 820 Bytes
33564cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const admin = require('firebase-admin');
const dotenv = require('dotenv');

dotenv.config();

// Logic: Check if we are in production (HuggingFace) or Local
// In production, we'll parse the JSON string from env vars.
// Locally, we look for the file.

let serviceAccount;

try {
  if (process.env.FIREBASE_SERVICE_ACCOUNT) {
    // Production: Use Env Variable
    serviceAccount = JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT);
  } else {
    // Local: Use file
    serviceAccount = require('../serviceAccountKey.json');
  }

  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount)
  });

  console.log("πŸ”₯ Firebase Admin Initialized Successfully");
} catch (error) {
  console.error("❌ Firebase Admin Init Error:", error.message);
}

const db = admin.firestore();
module.exports = { db };