From c00f991b1ee44c9cddfdd6a71d6b59c606e7328a Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:39:52 +0000 Subject: [PATCH] Fix: Prevent logout on email change cancellation --- src/components/settings/AccountProfileTab.tsx | 9 +++------ src/hooks/useAuth.tsx | 6 ++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/settings/AccountProfileTab.tsx b/src/components/settings/AccountProfileTab.tsx index 45bb8226..ed836766 100644 --- a/src/components/settings/AccountProfileTab.tsx +++ b/src/components/settings/AccountProfileTab.tsx @@ -34,7 +34,7 @@ const profileSchema = z.object({ type ProfileFormData = z.infer; export function AccountProfileTab() { - const { user, profile, refreshProfile, pendingEmail } = useAuth(); + const { user, profile, refreshProfile, pendingEmail, clearPendingEmail } = useAuth(); const { toast } = useToast(); const [loading, setLoading] = useState(false); const [avatarLoading, setAvatarLoading] = useState(false); @@ -173,11 +173,8 @@ export function AccountProfileTab() { throw new Error(data?.error || 'Failed to cancel email change'); } - // Force refresh the session to get updated user state - const { error: refreshError } = await supabase.auth.refreshSession(); - if (refreshError) { - console.error('Session refresh error:', refreshError); - } + // Clear the pending email state immediately without refreshing session + clearPendingEmail(); // Update Novu subscriber back to current email if (notificationService.isEnabled()) { diff --git a/src/hooks/useAuth.tsx b/src/hooks/useAuth.tsx index 0768c72c..7b339f65 100644 --- a/src/hooks/useAuth.tsx +++ b/src/hooks/useAuth.tsx @@ -11,6 +11,7 @@ interface AuthContextType { pendingEmail: string | null; signOut: () => Promise; refreshProfile: () => Promise; + clearPendingEmail: () => void; } const AuthContext = createContext(undefined); @@ -152,6 +153,10 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { } }; + const clearPendingEmail = () => { + setPendingEmail(null); + }; + const value = { user, session, @@ -160,6 +165,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { pendingEmail, signOut, refreshProfile, + clearPendingEmail, }; return {children};