horapi / src /firebase.js
ShieldX's picture
Upload 5 files
33564cc verified
raw
history blame contribute delete
820 Bytes
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 };