Skip to content

Commit a8cfcf4

Browse files
Fix: Improve login performance
Address slow login by ensuring the interface displays quickly, even if Firebase auth takes longer.
1 parent c242f63 commit a8cfcf4

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

src/contexts/AuthContext.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,18 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
2424
const [loading, setLoading] = useState(true);
2525

2626
useEffect(() => {
27-
console.log('🔐 AuthProvider - Démarrage ULTRA-RAPIDE');
28-
29-
// Timeout de 500ms maximum pour éviter les blocages
30-
const quickTimeout = setTimeout(() => {
31-
console.log('🔐 TIMEOUT 500ms - affichage immédiat');
32-
setLoading(false);
33-
}, 500);
27+
console.log('🔐 AuthProvider - Initialisation stable');
3428

3529
const unsubscribe = onAuthStateChanged(auth, (user) => {
3630
console.log('🔐 Auth state reçu:', user ? 'CONNECTÉ' : 'DÉCONNECTÉ');
37-
clearTimeout(quickTimeout);
3831
setUser(user);
3932
setLoading(false);
4033
}, (error) => {
4134
console.error('🚨 Erreur Auth:', error);
42-
clearTimeout(quickTimeout);
4335
setLoading(false);
4436
});
4537

46-
return () => {
47-
clearTimeout(quickTimeout);
48-
unsubscribe();
49-
};
38+
return unsubscribe;
5039
}, []);
5140

5241
const signInWithEmail = async (email: string, password: string) => {

src/lib/firebase.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import { initializeApp } from "firebase/app";
2+
import { initializeApp, getApps, getApp } from "firebase/app";
33
import { getAuth, GoogleAuthProvider } from "firebase/auth";
44
import { getFirestore } from "firebase/firestore";
55

@@ -32,7 +32,8 @@ const firebaseConfig = {
3232

3333
console.log('🔥 Firebase config chargée depuis les variables d\'environnement');
3434

35-
const app = initializeApp(firebaseConfig);
35+
// Éviter la double initialisation de Firebase
36+
const app = getApps().length === 0 ? initializeApp(firebaseConfig) : getApp();
3637

3738
export const auth = getAuth(app);
3839
export const db = getFirestore(app);

0 commit comments

Comments
 (0)