From daf4f6bf19e7cc66c27833575f5d33569f185b30 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Mon, 13 Oct 2025 17:01:15 +0000 Subject: [PATCH] Fix: Synchronize user and profile state updates --- src/components/auth/AuthButtons.tsx | 4 ++-- src/hooks/useAuth.tsx | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/auth/AuthButtons.tsx b/src/components/auth/AuthButtons.tsx index 85f72fc9..73ad476e 100644 --- a/src/components/auth/AuthButtons.tsx +++ b/src/components/auth/AuthButtons.tsx @@ -42,8 +42,8 @@ export function AuthButtons() { } }; - // Show loading skeleton during auth check - if (loading) { + // Show loading skeleton during auth check OR when user exists but profile hasn't loaded yet + if (loading || (user && !profile)) { return (
diff --git a/src/hooks/useAuth.tsx b/src/hooks/useAuth.tsx index 0884f9d6..d3aa4612 100644 --- a/src/hooks/useAuth.tsx +++ b/src/hooks/useAuth.tsx @@ -191,6 +191,8 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) { setSession(session); setUser(session.user); sessionVerifiedRef.current = true; + // Keep loading true until profile is fetched + setLoading(true); } else if (event === 'INITIAL_SESSION') { if (session?.user) { authLog('[Auth] INITIAL_SESSION with user, setting session'); @@ -296,10 +298,9 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) { profileFetchTimeoutRef.current = setTimeout(() => { fetchProfile(session.user.id, 0, () => { - if (shouldWaitForProfile) { - authLog('[Auth] Profile fetch complete, setting loading to false'); - setLoading(false); - } + // Always set loading to false after profile fetch for authenticated users + authLog('[Auth] Profile fetch complete, setting loading to false'); + setLoading(false); }); profileFetchTimeoutRef.current = null; }, 0);