Revert "M2: gate storage init on STORAGE mode (firebase vs ws/memory)"

This reverts commit 3e84f28325.
This commit is contained in:
david raistrick
2026-06-29 12:03:57 -04:00
parent 74b4c2c42d
commit e843acdf8a
+22 -41
View File
@@ -1,7 +1,7 @@
import React, { useState, useEffect, useRef, useMemo } from 'react'; import React, { useState, useEffect, useRef, useMemo } from 'react';
import { initializeApp } from './storage'; import { initializeApp } from './storage';
import { getAuth, signInAnonymously, onAuthStateChanged, signInWithCustomToken } from './storage'; import { getAuth, signInAnonymously, onAuthStateChanged, signInWithCustomToken } from './storage';
import { getFirestore, doc, setDoc, addDoc, collection, onSnapshot, updateDoc, deleteDoc, query, orderBy, limit, writeBatch, getStorage, getStorageMode } from './storage'; import { getFirestore, doc, setDoc, addDoc, collection, onSnapshot, updateDoc, deleteDoc, query, orderBy, limit, writeBatch, getStorage } from './storage';
import { import {
PlusCircle, Users, Swords, Trash2, Eye, Edit3, Save, XCircle, ChevronsUpDown, PlusCircle, Users, Swords, Trash2, Eye, Edit3, Save, XCircle, ChevronsUpDown,
UserCheck, UserX, HeartCrack, HeartPulse, Zap, EyeOff, ExternalLink, AlertTriangle, UserCheck, UserX, HeartCrack, HeartPulse, Zap, EyeOff, ExternalLink, AlertTriangle,
@@ -97,40 +97,29 @@ let db;
let auth; let auth;
let storage; let storage;
const STORAGE_MODE = getStorageMode(); // Initialize Firebase
const initializeFirebase = () => {
const requiredKeys = ['apiKey', 'authDomain', 'projectId', 'appId'];
const missingKeys = requiredKeys.filter(key => !firebaseConfig[key]);
// Initialize storage backend. firebase mode = real SDK init. if (missingKeys.length > 0) {
// ws/memory mode = mock auth, no firebase. console.error(`CRITICAL: Missing Firebase config values: ${missingKeys.join(', ')}`);
const initializeStorage = () => { return false;
if (STORAGE_MODE === 'firebase') {
const requiredKeys = ['apiKey', 'authDomain', 'projectId', 'appId'];
const missingKeys = requiredKeys.filter(key => !firebaseConfig[key]);
if (missingKeys.length > 0) {
console.error(`CRITICAL: Missing Firebase config values: ${missingKeys.join(', ')}`);
return false;
}
try {
app = initializeApp(firebaseConfig);
db = getFirestore(app);
auth = getAuth(app);
storage = getStorage();
return true;
} catch (error) {
console.error("Error initializing Firebase:", error);
return false;
}
} }
// ws / memory mode: stub auth so App's anon-sign-in path works. try {
const FAKE_USER = { uid: 'local-user', isAnonymous: true }; app = initializeApp(firebaseConfig);
auth = { db = getFirestore(app);
currentUser: FAKE_USER, auth = getAuth(app);
}; storage = getStorage();
storage = getStorage(); return true;
return true; } catch (error) {
console.error("Error initializing Firebase:", error);
return false;
}
}; };
const isInitialized = initializeStorage(); const isFirebaseInitialized = initializeFirebase();
// ============================================================================ // ============================================================================
// FIRESTORE PATH HELPERS // FIRESTORE PATH HELPERS
@@ -2815,20 +2804,12 @@ function App() {
} }
if (!auth) { if (!auth) {
setError("Auth not initialized."); setError("Firebase Auth not initialized. Check your Firebase configuration.");
setIsLoading(false); setIsLoading(false);
setIsAuthReady(false); setIsAuthReady(false);
return; return;
} }
// ws/memory mode: stub auth, no SDK sign-in. Unblock UI immediately.
if (STORAGE_MODE !== 'firebase') {
setUserId(auth.currentUser?.uid || 'local-user');
setIsAuthReady(true);
setIsLoading(false);
return;
}
const initAuth = async () => { const initAuth = async () => {
try { try {
const token = window.__initial_auth_token; const token = window.__initial_auth_token;
@@ -2862,11 +2843,11 @@ function App() {
return () => unsubscribe(); return () => unsubscribe();
}, []); }, []);
if (!isInitialized || !auth) { if (!isFirebaseInitialized || !db || !auth) {
return ( return (
<ErrorDisplay <ErrorDisplay
critical critical
message={`${STORAGE_MODE === 'firebase' ? 'Firebase' : 'Storage'} is not properly configured. Check your .env.local file and ensure all REACT_APP_* variables are correctly set.`} message="Firebase is not properly configured or initialized. Please check your .env.local file and ensure all REACT_APP_FIREBASE_... variables are correctly set."
/> />
); );
} }