Skip to content

Commit 0bf3cd3

Browse files
Fix: Address affiliate count not updating
Added detailed debug logs within the `useAffiliates.ts` hook to help diagnose why the affiliate count isn't updating.
1 parent f29f376 commit 0bf3cd3

File tree

2 files changed

+19
-29
lines changed

2 files changed

+19
-29
lines changed

src/hooks/useAuth.tsx

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,30 @@ import { useRetry } from './useRetry';
1414

1515
export const useAuth = () => {
1616
const [user, setUser] = useState<User | null>(null);
17-
const [loading, setLoading] = useState(false); // Changé de true à false pour affichage immédiat
17+
const [loading, setLoading] = useState(true);
1818
const [initialized, setInitialized] = useState(false);
1919
const { handleError } = useErrorHandler();
2020
const { executeWithRetry } = useRetry({ maxRetries: 2 });
2121

2222
useEffect(() => {
2323
console.log('🔐 Initialisation de l\'authentification...');
2424

25-
// Délai très court pour permettre l'affichage de l'UI
26-
const initTimer = setTimeout(() => {
27-
const unsubscribe = onAuthStateChanged(auth, (user) => {
28-
console.log('🔐 État d\'authentification changé:', user ? 'Connecté' : 'Déconnecté');
29-
setUser(user);
30-
setLoading(false);
31-
setInitialized(true);
32-
}, (error) => {
33-
console.error('🚨 Erreur d\'authentification:', error);
34-
handleError(error, {
35-
showToast: true,
36-
logError: true
37-
});
38-
setLoading(false);
39-
setInitialized(true);
25+
const unsubscribe = onAuthStateChanged(auth, (user) => {
26+
console.log('🔐 État d\'authentification changé:', user ? 'Connecté' : 'Déconnecté');
27+
setUser(user);
28+
setLoading(false);
29+
setInitialized(true);
30+
}, (error) => {
31+
console.error('🚨 Erreur d\'authentification:', error);
32+
handleError(error, {
33+
showToast: true,
34+
logError: true
4035
});
36+
setLoading(false);
37+
setInitialized(true);
38+
});
4139

42-
return () => {
43-
clearTimeout(initTimer);
44-
unsubscribe();
45-
};
46-
}, 100); // Délai minimal pour l'affichage
47-
48-
return () => clearTimeout(initTimer);
40+
return unsubscribe;
4941
}, [handleError]);
5042

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

src/pages/Index.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ const Index = () => {
88
const { user, loading, initialized } = useAuth();
99
const { t } = useTranslation();
1010

11-
// Affichage immédiat du formulaire pendant l'initialisation
12-
if (!initialized) {
13-
return <AuthForm />;
14-
}
11+
console.log('🔍 Index render - user:', !!user, 'loading:', loading, 'initialized:', initialized);
1512

16-
if (loading) {
13+
// Pendant l'initialisation de Firebase
14+
if (!initialized || loading) {
1715
return (
18-
<div className="min-h-screen flex items-center justify-center">
16+
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50/50 via-white to-purple-50/50">
1917
<div className="text-center">
2018
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-4"></div>
2119
<p className="text-gray-600">{t('loading')}</p>

0 commit comments

Comments
 (0)