From 65d1262b2fbeecab07e4806acd91664c9246b628 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sun, 5 Oct 2025 03:01:46 +0000 Subject: [PATCH] Purge legacy mock state cgen-3b2d4b3d2140486784ff46322272c16b --- client/contexts/AuthContext.tsx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/client/contexts/AuthContext.tsx b/client/contexts/AuthContext.tsx index 627a6d12..e6fbf62a 100644 --- a/client/contexts/AuthContext.tsx +++ b/client/contexts/AuthContext.tsx @@ -150,6 +150,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ const [session, setSession] = useState(null); const [loading, setLoading] = useState(true); const rewardsActivatedRef = useRef(false); + const storageClearedRef = useRef(false); useEffect(() => { // Add timeout to ensure loading doesn't get stuck @@ -158,6 +159,22 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ setLoading(false); }, 5000); + if (!storageClearedRef.current && typeof window !== "undefined") { + try { + [ + "mock_user", + "mock_profile", + "mock_linked_provider_map", + "demo_profiles", + "demo_posts", + "demo_seed_v1", + ].forEach((key) => window.localStorage.removeItem(key)); + storageClearedRef.current = true; + } catch { + storageClearedRef.current = true; + } + } + // Get initial session supabase.auth .getSession() @@ -531,8 +548,14 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ if (typeof window !== "undefined") { try { window.localStorage.removeItem("onboarding_complete"); + const shouldRemove = (key: string) => + key.startsWith("sb-") || + key.includes("supabase") || + key.startsWith("mock_") || + key.startsWith("demo_"); + Object.keys(window.localStorage) - .filter((key) => key.startsWith("sb-") || key.includes("supabase")) + .filter(shouldRemove) .forEach((key) => { window.localStorage.removeItem(key); });