Spaces:
Sleeping
Sleeping
Download src/config/firebase.js from Huzaifa1435/Carpool_final: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/spaces/Huzaifa1435/Carpool_final/resolve/main/src/config/firebase.js
- Command line
-
hf download hf://spaces/Huzaifa1435/Carpool_final/src/config/firebase.js
-
curl -L -o firebase.js https://huggingface.co/spaces/Huzaifa1435/Carpool_final/resolve/main/src/config/firebase.js
2.74 kB
| const admin = require('firebase-admin'); | |
| require('dotenv').config(); | |
| // Log environment check (for debugging) | |
| console.log('π§ Initializing Firebase...'); | |
| console.log('π Checking environment variables:'); | |
| console.log(' - FIREBASE_PROJECT_ID:', process.env.FIREBASE_PROJECT_ID ? 'β Set' : 'β Missing'); | |
| console.log(' - FIREBASE_PRIVATE_KEY:', process.env.FIREBASE_PRIVATE_KEY ? 'β Set' : 'β Missing'); | |
| console.log(' - FIREBASE_CLIENT_EMAIL:', process.env.FIREBASE_CLIENT_EMAIL ? 'β Set' : 'β Missing'); | |
| // Check if Firebase credentials exist | |
| if (!process.env.FIREBASE_PROJECT_ID || !process.env.FIREBASE_PRIVATE_KEY || !process.env.FIREBASE_CLIENT_EMAIL) { | |
| console.error('β Firebase credentials missing! Please set environment variables.'); | |
| console.error('Required: FIREBASE_PROJECT_ID, FIREBASE_PRIVATE_KEY, FIREBASE_CLIENT_EMAIL'); | |
| // Export empty objects to prevent app crash (but features won't work) | |
| module.exports = { | |
| admin: admin, | |
| db: null, | |
| auth: null, | |
| messaging: null | |
| }; | |
| } else { | |
| try { | |
| // Initialize Firebase only if not already initialized | |
| if (!admin.apps.length) { | |
| const privateKey = String(process.env.FIREBASE_PRIVATE_KEY) | |
| .trim() | |
| .replace(/^['"]|['"]$/g, '') | |
| .replace(/\\n/g, '\n') | |
| .replace(/\r/g, ''); | |
| admin.initializeApp({ | |
| credential: admin.credential.cert({ | |
| projectId: process.env.FIREBASE_PROJECT_ID, | |
| privateKey, | |
| clientEmail: process.env.FIREBASE_CLIENT_EMAIL, | |
| }), | |
| }); | |
| console.log('β Firebase initialized successfully!'); | |
| console.log(`π Project: ${process.env.FIREBASE_PROJECT_ID}`); | |
| } else { | |
| console.log('β Firebase already initialized'); | |
| } | |
| // Initialize Firestore, Auth, Messaging | |
| const db = admin.firestore(); | |
| const auth = admin.auth(); | |
| const messaging = admin.messaging(); | |
| console.log('β Firestore connected'); | |
| console.log('β Firebase Auth ready'); | |
| console.log('β Firebase Messaging ready'); | |
| // Export everything | |
| module.exports = { | |
| admin, | |
| db, | |
| auth, | |
| messaging | |
| }; | |
| } catch (error) { | |
| console.error('β Firebase initialization error:', error.message); | |
| console.error('Stack:', error.stack); | |
| // Export with error - app will handle gracefully | |
| module.exports = { | |
| admin: admin, | |
| db: null, | |
| auth: null, | |
| messaging: null | |
| }; | |
| } | |
| } | |