From acfec5abe5491035b9142a4400f39bc8663a4085 Mon Sep 17 00:00:00 2001 From: AI Assistant Date: Mon, 9 Mar 2026 12:48:03 +0200 Subject: [PATCH] fix(auth): move loading check after hooks to fix Rules of Hooks violation Early return before useCallback/useMemo caused React error #310 (different hook count between renders). Loading spinner now renders after all hooks are called unconditionally. Co-Authored-By: Claude Opus 4.6 --- src/core/auth/auth-provider.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/auth/auth-provider.tsx b/src/core/auth/auth-provider.tsx index 638a88e..f91719d 100644 --- a/src/core/auth/auth-provider.tsx +++ b/src/core/auth/auth-provider.tsx @@ -30,16 +30,7 @@ interface AuthProviderProps { function AuthProviderInner({ children }: AuthProviderProps) { const { data: session, status } = useSession(); - // Show loading spinner while session is being validated - if (status === "loading") { - return ( -
-
-
- ); - } - - // Use session user if available, otherwise fallback to stub in dev mode + // Derive user from session (all hooks must be called unconditionally) const user: User | null = session?.user ? { id: (session.user as any).id || "unknown", @@ -79,6 +70,15 @@ function AuthProviderInner({ children }: AuthProviderProps) { [user, hasRole, canAccessModule], ); + // Show loading spinner while session is being validated (after all hooks) + if (status === "loading") { + return ( +
+
+
+ ); + } + return {children}; }