Fix Firebase config to handle missing credentials gracefully
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -13,18 +13,29 @@ const firebaseConfig = {
|
|||||||
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
|
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only initialize if we have the API key (skip during build)
|
// Only initialize if we have the API key (skip during build and if no config)
|
||||||
let _app: FirebaseApp | undefined;
|
let _app: FirebaseApp | undefined;
|
||||||
let _auth: Auth | undefined;
|
let _auth: Auth | undefined;
|
||||||
let _db: Firestore | undefined;
|
let _db: Firestore | undefined;
|
||||||
let _storage: FirebaseStorage | undefined;
|
let _storage: FirebaseStorage | undefined;
|
||||||
|
|
||||||
if (typeof window !== 'undefined' || firebaseConfig.apiKey) {
|
// Check if Firebase is properly configured
|
||||||
// Initialize Firebase (client-side only, safe for browser)
|
const isFirebaseConfigured = firebaseConfig.apiKey &&
|
||||||
_app = getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0];
|
firebaseConfig.authDomain &&
|
||||||
_auth = getAuth(_app);
|
firebaseConfig.projectId;
|
||||||
_db = getFirestore(_app);
|
|
||||||
_storage = getStorage(_app);
|
if (isFirebaseConfigured && (typeof window !== 'undefined' || firebaseConfig.apiKey)) {
|
||||||
|
try {
|
||||||
|
// Initialize Firebase (client-side only, safe for browser)
|
||||||
|
_app = getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0];
|
||||||
|
_auth = getAuth(_app);
|
||||||
|
_db = getFirestore(_app);
|
||||||
|
_storage = getStorage(_app);
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Firebase initialization skipped - no credentials configured');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn('Firebase not configured - using PostgreSQL backend');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export with type assertions - these will be defined at runtime in the browser
|
// Export with type assertions - these will be defined at runtime in the browser
|
||||||
|
|||||||
Reference in New Issue
Block a user