From 6e57236d93710f6ad9e7ac5ca3f01bc8ddd45dc2 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 30 Sep 2025 23:00:42 +0000 Subject: [PATCH] Improve signOut resilience and clear client state cgen-b67da32042584983a1bd455f884a1230 --- client/contexts/AuthContext.tsx | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/client/contexts/AuthContext.tsx b/client/contexts/AuthContext.tsx index a6dd7d5a..5f7f7cd6 100644 --- a/client/contexts/AuthContext.tsx +++ b/client/contexts/AuthContext.tsx @@ -417,16 +417,42 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ [user, refreshAuthState], ); + const clearClientAuthState = useCallback(() => { + setUser(null); + setProfile(null); + setRoles([]); + setSession(null); + if (typeof window !== "undefined") { + try { + window.localStorage.removeItem("onboarding_complete"); + window.localStorage.removeItem("supabase.auth.token"); + window.localStorage.removeItem("supabase.auth.refresh_token"); + } catch {} + } + }, []); + const signOut = async () => { + setLoading(true); try { const { error } = await supabase.auth.signOut(); if (error) throw error; + clearClientAuthState(); + aethexToast.info({ + title: "Signed out", + description: "You have been signed out successfully.", + }); } catch (error: any) { + console.warn("Supabase signOut failed, forcing local cleanup:", error); + clearClientAuthState(); aethexToast.error({ - title: "Sign out failed", - description: error.message, + title: "Sign out issue", + description: + error?.message || + "We had trouble contacting the auth service, but local data was cleared.", }); throw error; + } finally { + setLoading(false); } };