Procházet zdrojové kódy

fix: auth init always sets loading=false so app renders after reload

Claude Dev před 1 měsícem
rodič
revize
18c7a1d31c
1 změnil soubory, kde provedl 3 přidání a 7 odebrání
  1. 3 7
      src/lib/auth-context.tsx

+ 3 - 7
src/lib/auth-context.tsx

@@ -46,12 +46,10 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
       } catch {
         localStorage.removeItem('vidreview_token');
         localStorage.removeItem('vidreview_user');
-        setLoading(false);
-        return;
       }
-    } else {
-      setLoading(false);
     }
+    // Always set loading false — spinner only shows while checking session
+    setLoading(false);
   // eslint-disable-next-line react-hooks/exhaustive-deps
   }, []);
 
@@ -61,9 +59,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
     usersApi.getMe(initToken).then(({ user: u }) => {
       setUser(u);
       localStorage.setItem('vidreview_user', JSON.stringify(u));
-    }).catch(() => { /* ignore */ }).finally(() => {
-      setLoading(false);
-    });
+    }).catch(() => { /* ignore — stale localStorage still shown */ });
   // eslint-disable-next-line react-hooks/exhaustive-deps
   }, [initToken]);