Skip to content

Fix mobile "Add another account" redirect loop via sessionStorage backup#209

Merged
sirjamesgray merged 1 commit into
copilot/fix-switch-account-dropdown-actionfrom
copilot/fix-account-switching-issue
May 11, 2026
Merged

Fix mobile "Add another account" redirect loop via sessionStorage backup#209
sirjamesgray merged 1 commit into
copilot/fix-switch-account-dropdown-actionfrom
copilot/fix-account-switching-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

On iOS PWA (and some Android PWA), clicking "Add another account" immediately bounced back to the dashboard. The existing ?switchAccount=1 URL param guard was unreliable because window.location.href in PWA standalone mode can behave as a soft navigation — keeping AuthProvider in its already-resolved state (isLoading: false, isAuthenticated: true) — leaving a timing window where the redirect guard fires before useSearchParams() reflects the new URL.

Changes

  • MobileAccountMenu.tsx — write sessionStorage.setItem('wewrite_adding_account', '1') synchronously before the window.location.href navigation. The flag is always set prior to any React effect on the destination page.

  • login-form.tsx — extend the redirect guard to also check sessionStorage as a fallback when hasSearchParam misses the URL param:

const sessionHasAddingAccount = (() => {
  try { return sessionStorage.getItem('wewrite_adding_account') === '1'; } catch { return false; }
})();
if (!authLoading && isAuthenticated && !urlHasSwitchAccount && !sessionHasAddingAccount) {
  router.push('/home');
}
  • login-form.tsx — add a cleanup useEffect that removes the flag on unmount, preventing it from leaking into future unrelated visits to the login page.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
wewrite Ready Ready Preview, Comment May 11, 2026 3:14am

Request Review

@sirjamesgray sirjamesgray marked this pull request as ready for review May 11, 2026 03:14
@sirjamesgray sirjamesgray merged commit 74efc0d into copilot/fix-switch-account-dropdown-action May 11, 2026
3 checks passed
@sirjamesgray sirjamesgray deleted the copilot/fix-account-switching-issue branch May 11, 2026 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants