Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/components/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import { getAuth } from "firebase/auth";
import { getDatabase } from "firebase/database";
import { getFirestore } from "firebase/firestore";

// ✅ Use .env variables (set these in your .env file)
// If no Firebase config is provided, use dummy config for development
// ✅ Use .env variables if provided (won't break if missing)
const firebaseConfig = {
apiKey: process.env.REACT_APP_FIREBASE_API_KEY || "demo-api-key",
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN || "demo-project.firebaseapp.com",
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID || "demo-project",
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET || "demo-project.appspot.com",
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID || "123456789",
appId: process.env.REACT_APP_FIREBASE_APP_ID || "1:123456789:web:demo",
// 👇 Only include if you need analytics
measurementId: process.env.REACT_APP_FIREBASE_MEASUREMENT_ID || "G-DEMO123",
// 👇 Only include if you enable Realtime Database
databaseURL: process.env.REACT_APP_FIREBASE_DATABASE_URL || "https://demo-project.firebaseio.com",
};

Expand All @@ -32,25 +29,27 @@ try {
firestoreDb = getFirestore(app);
} catch (error) {
console.warn("Firebase initialization failed:", error.message);
console.warn("Firebase features will be disabled. Please configure your .env file with valid Firebase credentials.");
// Create mock objects to prevent app crashes
console.warn("Firebase features will be disabled. Using demo mocks for PR testing.");

// ✅ Mock Firebase to prevent crashes
auth = {
currentUser: null,
onAuthStateChanged: () => () => {},
signInWithEmailAndPassword: () => Promise.reject(new Error("Firebase not configured")),
signInWithPopup: () => Promise.reject(new Error("Firebase not configured")),
createUserWithEmailAndPassword: () => Promise.reject(new Error("Firebase not configured")),
signInWithEmailAndPassword: () =>
Promise.resolve({ user: { uid: "demo-user", email: "[email protected]" } }),
createUserWithEmailAndPassword: () =>
Promise.resolve({ user: { uid: "demo-user", email: "[email protected]" } }),
signInWithPopup: () => Promise.resolve({ user: { uid: "demo-user", email: "[email protected]" } }),
signOut: () => Promise.resolve(),
};

realtimeDb = {
ref: () => ({
set: () => Promise.resolve(),
get: () => Promise.resolve({ val: () => null }),
}),
};

firestoreDb = {
collection: () => ({
doc: () => ({
Expand Down