From b81cada34b212bb35f47811a59a1ea75b2a65159 Mon Sep 17 00:00:00 2001 From: Tony Giorgio Date: Thu, 30 Jan 2025 21:35:08 -0600 Subject: [PATCH] Fix potential race condition for sign out --- frontend/src/components/AccountMenu.tsx | 27 +++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/AccountMenu.tsx b/frontend/src/components/AccountMenu.tsx index cd9a1a47..87bcd2d2 100644 --- a/frontend/src/components/AccountMenu.tsx +++ b/frontend/src/components/AccountMenu.tsx @@ -92,12 +92,27 @@ export function AccountMenu() { } }; - function signOut() { - os.signOut(); - sessionStorage.removeItem("maple_billing_token"); - router.invalidate().finally(() => { - router.navigate({ to: "/" }); - }); + async function signOut() { + try { + // Try to clear billing token first + try { + getBillingService().clearToken(); + } catch (error) { + // Fallback to direct session storage removal if billing service fails + sessionStorage.removeItem("maple_billing_token"); + } + + // Sign out from OpenSecret + await os.signOut(); + + // Navigate after everything is done + await router.invalidate(); + await router.navigate({ to: "/" }); + } catch (error) { + console.error("Error during sign out:", error); + // Force reload as last resort + window.location.href = "/"; + } } return (