From 24d9fd480f24a1d1ff88236b10cdd92dafea1f7a Mon Sep 17 00:00:00 2001 From: mohiit1502 Date: Sun, 2 Aug 2026 03:06:45 +0530 Subject: [PATCH] fix(auth): clear active tokens before iam.login redirect to prevent init() race on callback page --- src/hooks/useAccountSessions.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/hooks/useAccountSessions.ts b/src/hooks/useAccountSessions.ts index dd6595f..9cd2a7a 100644 --- a/src/hooks/useAccountSessions.ts +++ b/src/hooks/useAccountSessions.ts @@ -158,7 +158,12 @@ export function useAccountSessions(): AccountSessionsState { } // No cached tokens — need full OIDC login for this account. - // prompt=login forces credential entry even if IAM has a session. + // Clear active tokens so iam.init() on the /callback page doesn't + // race and re-authenticate as the old user before handleCallback + // can exchange the code for the new user's tokens. + for (const key of IAM_TOKEN_KEYS) { + try { localStorage.removeItem(key) } catch { /* non-fatal */ } + } void iam.login({ loginHint: account.email, prompt: 'login' }) }, [user])