@@ -14,38 +14,30 @@ import { useRetry } from './useRetry';
1414
1515export 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 ) => {
0 commit comments