From 6c9fad06806265eac554ef302b50878983a3be88 Mon Sep 17 00:00:00 2001 From: hughcrt Date: Fri, 1 Nov 2024 15:12:50 +0800 Subject: [PATCH] ok --- packages/frontend/utils/auth.tsx | 5 +++++ packages/frontend/utils/hooks.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/frontend/utils/auth.tsx b/packages/frontend/utils/auth.tsx index 95db188c..b3d95f37 100644 --- a/packages/frontend/utils/auth.tsx +++ b/packages/frontend/utils/auth.tsx @@ -9,6 +9,11 @@ export async function signOut() { const jwt = window.localStorage.getItem("auth-token"); window.localStorage.clear(); window.sessionStorage.clear(); + + // used by the useProjectIdStorage hook + const event = new Event("userSignedOut"); + window.dispatchEvent(event); + if (jwt) { const payload = decodeJwt(jwt); const email = payload.email as string; diff --git a/packages/frontend/utils/hooks.ts b/packages/frontend/utils/hooks.ts index 49db57a9..e498b8e2 100644 --- a/packages/frontend/utils/hooks.ts +++ b/packages/frontend/utils/hooks.ts @@ -91,6 +91,18 @@ export function useProjectIdStorage() { } }, [projectId]); + useEffect(() => { + const handleSignOut = () => { + setProjectId(null); + }; + + window.addEventListener("userSignedOut", handleSignOut); + + return () => { + window.removeEventListener("userSignedOut", handleSignOut); + }; + }, []); + return [projectId, setProjectId] as const; }