Skip to content

Commit 202f5f5

Browse files
Fix: Network request failed during login
Fixed the "auth/network-request-failed" error, which was preventing login.
1 parent ff1c716 commit 202f5f5

File tree

2 files changed

+45
-54
lines changed

2 files changed

+45
-54
lines changed

src/contexts/AuthContext.tsx

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

2626
useEffect(() => {
27-
console.log('🔐 AuthProvider - Initialisation ULTRA-RAPIDE optimisée');
27+
console.log('🔐 AuthProvider - Initialisation SIMPLE');
2828

29-
// Vérifier d'abord le cache local pour un affichage immédiat
30-
const cachedAuthState = localStorage.getItem('firebase_auth_cache');
31-
if (cachedAuthState) {
32-
console.log('🔐 Cache auth trouvé - affichage immédiat');
33-
setLoading(false);
34-
}
35-
36-
// Timeout encore plus court : 500ms maximum
37-
const ultraQuickTimeoutId = setTimeout(() => {
38-
console.log('🔐 Timeout 500ms atteint - FORCER l\'affichage');
39-
setLoading(false);
40-
}, 500);
41-
4229
const unsubscribe = onAuthStateChanged(auth, (user) => {
4330
console.log('🔐 Firebase Auth state changed:', user ? 'CONNECTÉ' : 'DÉCONNECTÉ');
4431
setUser(user);
4532
setLoading(false);
46-
clearTimeout(ultraQuickTimeoutId);
47-
48-
// Mettre en cache l'état d'authentification
49-
localStorage.setItem('firebase_auth_cache', user ? 'authenticated' : 'anonymous');
5033

5134
if (user) {
5235
console.log('🔐 Utilisateur authentifié:', user.uid);
5336
} else {
5437
console.log('🔐 Utilisateur déconnecté');
55-
localStorage.removeItem('firebase_auth_cache');
5638
}
39+
}, (error) => {
40+
console.error('🚨 Erreur Auth State Changed:', error);
41+
setLoading(false);
5742
});
5843

5944
return () => {
6045
unsubscribe();
61-
clearTimeout(ultraQuickTimeoutId);
6246
};
6347
}, []);
6448

6549
const signInWithEmail = async (email: string, password: string) => {
6650
console.log('🔐 Tentative connexion email...');
67-
return signInWithEmailAndPassword(auth, email, password);
51+
try {
52+
const result = await signInWithEmailAndPassword(auth, email, password);
53+
console.log('✅ Connexion email réussie');
54+
return result;
55+
} catch (error) {
56+
console.error('❌ Erreur connexion email:', error);
57+
throw error;
58+
}
6859
};
6960

7061
const signUpWithEmail = async (email: string, password: string) => {
7162
console.log('🔐 Tentative création compte...');
72-
return createUserWithEmailAndPassword(auth, email, password);
63+
try {
64+
const result = await createUserWithEmailAndPassword(auth, email, password);
65+
console.log('✅ Création compte réussie');
66+
return result;
67+
} catch (error) {
68+
console.error('❌ Erreur création compte:', error);
69+
throw error;
70+
}
7371
};
7472

7573
const signInWithGoogle = async () => {
7674
console.log('🔐 Tentative connexion Google...');
77-
return signInWithPopup(auth, googleProvider);
75+
try {
76+
const result = await signInWithPopup(auth, googleProvider);
77+
console.log('✅ Connexion Google réussie');
78+
return result;
79+
} catch (error) {
80+
console.error('❌ Erreur connexion Google:', error);
81+
throw error;
82+
}
7883
};
7984

8085
return (

src/lib/firebase.ts

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,33 @@
11

2-
32
import { initializeApp } from "firebase/app";
4-
import { getAuth, GoogleAuthProvider, connectAuthEmulator } from "firebase/auth";
5-
import { getFirestore, connectFirestoreEmulator } from "firebase/firestore";
3+
import { getAuth, GoogleAuthProvider } from "firebase/auth";
4+
import { getFirestore } from "firebase/firestore";
65

6+
// Configuration Firebase fixe (sans variables d'environnement pour test)
77
const firebaseConfig = {
8-
apiKey: import.meta.env.VITE_FIREBASE_API_KEY || "AIzaSyAlHsC-w7Sx18XKJ6dIcxvqj-AUdqkjqSE",
9-
authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN || "refspring-8c3ac.firebaseapp.com",
10-
databaseURL: import.meta.env.VITE_FIREBASE_DATABASE_URL || "https://refspring-8c3ac-default-rtdb.europe-west1.firebasedatabase.app",
11-
projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID || "refspring-8c3ac",
12-
storageBucket: import.meta.env.VITE_FIREBASE_STORAGE_BUCKET || "refspring-8c3ac.firebasestorage.app",
13-
messagingSenderId: import.meta.env.VITE_FIREBASE_MESSAGING_SENDER_ID || "519439687826",
14-
appId: import.meta.env.VITE_FIREBASE_APP_ID || "1:519439687826:web:c0644e224f4ca23b57864b",
15-
measurementId: import.meta.env.VITE_FIREBASE_MEASUREMENT_ID || "G-QNK35Y7EE4"
8+
apiKey: "AIzaSyAlHsC-w7Sx18XKJ6dIcxvqj-AUdqkjqSE",
9+
authDomain: "refspring-8c3ac.firebaseapp.com",
10+
databaseURL: "https://refspring-8c3ac-default-rtdb.europe-west1.firebasedatabase.app",
11+
projectId: "refspring-8c3ac",
12+
storageBucket: "refspring-8c3ac.firebasestorage.app",
13+
messagingSenderId: "519439687826",
14+
appId: "1:519439687826:web:c0644e224f4ca23b57864b",
15+
measurementId: "G-QNK35Y7EE4"
1616
};
1717

18-
// Initialize Firebase avec optimisations de performance
18+
console.log('🔥 Firebase config DIRECT:', firebaseConfig);
19+
20+
// Initialize Firebase
1921
const app = initializeApp(firebaseConfig);
2022

21-
// Initialize Firebase services avec configuration optimisée
23+
// Initialize Firebase services
2224
export const auth = getAuth(app);
2325
export const db = getFirestore(app);
2426

25-
// Configuration ultra-rapide pour Google Auth
27+
// Configuration Google Auth simple
2628
export const googleProvider = new GoogleAuthProvider();
2729
googleProvider.setCustomParameters({
28-
prompt: 'select_account',
29-
hd: undefined // Pas de restriction de domaine pour plus de rapidité
30+
prompt: 'select_account'
3031
});
3132

32-
// Log optimisé en dev seulement
33-
if (import.meta.env.DEV) {
34-
console.log('🔥 Firebase config OPTIMISÉ pour la vitesse:', {
35-
projectId: firebaseConfig.projectId,
36-
authDomain: firebaseConfig.authDomain,
37-
usingEnvVars: !!import.meta.env.VITE_FIREBASE_API_KEY
38-
});
39-
}
40-
41-
// Analytics complètement désactivé pour éviter tout délai
42-
console.log('⚡ Firebase optimisé pour vitesse maximale - Analytics désactivé');
43-
44-
export const getAnalyticsInstance = () => null;
45-
4633
export default app;
47-

0 commit comments

Comments
 (0)