Skip to content

fix(experience): hide MFA back button after one-time token sign-in#8921

Merged
wangsijie merged 6 commits into
masterfrom
sijie-hide-mfa-back-one-time-token-974a
Jun 2, 2026
Merged

fix(experience): hide MFA back button after one-time token sign-in#8921
wangsijie merged 6 commits into
masterfrom
sijie-hide-mfa-back-one-time-token-974a

Conversation

@wangsijie
Copy link
Copy Markdown
Contributor

@wangsijie wangsijie commented Jun 1, 2026

Summary

Fixes #8841.

When users sign in with a one-time token (magic link) and are prompted to set up or verify MFA, navigating back could return to the consumed token page and trigger one_time_token.token_consumed.

This change removes the one-time token landing page from the browser history when redirecting to profile completion or MFA flows, so back navigation (in-app, browser, or hardware) no longer re-runs token verification.

Changes

  • Pass replace: true to useSubmitInteractionErrorHandler on the one-time token page so profile and MFA redirects replace the token page in history
  • Thread replace through useSendMfaVerificationCode for email/phone MFA verification redirects from the one-time token flow

Testing

Tested locally

Open in Web Open in Cursor 

When users sign in via a magic link, the token is consumed before MFA setup.
Navigating back retries verification and fails with token_consumed.

Track one-time token sign-in in session storage and hide the back control on
MFA setup screens until the interaction completes.

Co-authored-by: wangsijie <sijiewg@gmail.com>
@github-actions github-actions Bot added the bugfix label Jun 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

COMPARE TO master

Total Size Diff 📈 +229 Bytes

Diff by File
Name Diff
packages/experience/src/hooks/use-mfa-error-handler.ts 📈 +11 Bytes
packages/experience/src/hooks/use-send-mfa-verification-code.ts 📈 +166 Bytes
packages/experience/src/pages/OneTimeToken/index.tsx 📈 +52 Bytes

@github-actions github-actions Bot added the size/s label Jun 1, 2026
@wangsijie wangsijie marked this pull request as ready for review June 1, 2026 03:28
Copilot AI review requested due to automatic review settings June 1, 2026 03:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the one-time token MFA setup flow by hiding MFA back navigation so users cannot navigate back to a consumed magic-link token page.

Changes:

  • Adds a hideBack flag to MFA flow state validation.
  • Persists one-time-token sign-in state in session storage and clears it with interaction session storage.
  • Applies MFA back-navigation hiding across MFA setup pages.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/experience/src/types/guard.ts Extends MFA state guard with hideBack.
packages/experience/src/types/guard.test.ts Adds guard coverage for hideBack.
packages/experience/src/Providers/UserInteractionContextProvider/index.tsx Clears the one-time-token flag with interaction storage.
packages/experience/src/pages/OneTimeToken/index.tsx Sets the one-time-token sign-in flag after token verification.
packages/experience/src/pages/MfaOnboarding/index.tsx Hides navbar when MFA back navigation should be hidden.
packages/experience/src/pages/MfaBinding/index.tsx Hides navbar on MFA factor selection.
packages/experience/src/pages/MfaBinding/TotpBinding/index.tsx Hides navbar on TOTP binding.
packages/experience/src/pages/MfaBinding/WebAuthnBinding/index.tsx Hides navbar on WebAuthn binding.
packages/experience/src/pages/MfaBinding/VerificationCodeMfaBinding/index.tsx Hides navbar on verification-code MFA binding.
packages/experience/src/hooks/use-should-hide-mfa-back-navigation.ts Adds shared hook for MFA back-navigation visibility.
packages/experience/src/hooks/use-session-storages.ts Adds storage key and guard for one-time-token sign-in state.
packages/experience/src/hooks/use-mfa-error-handler.ts Passes hide-back state into MFA redirects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/experience/src/hooks/use-mfa-error-handler.ts Outdated
Comment thread packages/experience/src/hooks/use-session-storages.ts Outdated
Comment thread packages/experience/src/pages/OneTimeToken/index.tsx Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Hiding nav bar also hides MFA skip button
    • Added isBackHidden to NavBar to hide only the back button while keeping the skip button visible on MFA pages.

You can send follow-ups to the cloud agent here.

Comment thread packages/experience/src/pages/MfaOnboarding/index.tsx Outdated
Add isBackHidden to NavBar so one-time token flows can hide back
navigation without removing the skip button from SecondaryPageLayout.

Co-authored-by: wangsijie <sijiewg@gmail.com>
@github-actions github-actions Bot added size/s and removed size/s labels Jun 1, 2026
Comment thread packages/experience/src/hooks/use-mfa-error-handler.ts Outdated
Comment thread packages/experience/src/Providers/UserInteractionContextProvider/index.tsx Outdated
Comment thread packages/experience/src/hooks/use-should-hide-mfa-back-navigation.ts Outdated
Comment thread packages/experience/src/pages/OneTimeToken/index.tsx Outdated
Comment thread packages/experience/src/hooks/use-session-storages.ts Outdated
Comment thread packages/experience/src/pages/MfaBinding/index.tsx Outdated
Comment thread packages/experience/src/hooks/use-mfa-error-handler.ts Outdated
…ime token sign-in

Apply useShouldHideMfaBackNavigation to all MFA verification pages so
users signing in via one-time token cannot navigate back to the consumed
token page.

Co-authored-by: wangsijie <sijiewg@gmail.com>
Copilot AI review requested due to automatic review settings June 1, 2026 03:48
@github-actions github-actions Bot added size/m and removed size/s labels Jun 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Comment thread packages/experience/src/hooks/use-session-storages.ts Outdated
Comment thread packages/experience/src/pages/OneTimeToken/index.tsx Outdated
Comment thread packages/experience/src/hooks/use-should-hide-mfa-back-navigation.ts Outdated
…routes

Remove the OneTimeTokenSignIn sessionStorage flag when the user leaves
one-time-token and MFA routes so a later password sign-in does not
incorrectly hide the MFA back button.

Co-authored-by: wangsijie <sijiewg@gmail.com>
@github-actions github-actions Bot added size/m and removed size/m labels Jun 1, 2026
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 8041d9c. Configure here.

Comment thread packages/experience/src/Providers/UserInteractionContextProvider/index.tsx Outdated
…back

- Hide only the back control via isBackHidden; keep skip visible
- Remove redundant hideBack MFA flow state; rely on session flag only
- Stringify scalar session storage values for TypeScript compatibility
- Clear stale one-time token flag outside OTT/MFA routes safely in tests
Copilot AI review requested due to automatic review settings June 1, 2026 04:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Comment thread packages/experience/src/Providers/UserInteractionContextProvider/index.tsx Outdated
Copy link
Copy Markdown
Member

@charIeszhao charIeszhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify this by removing the consumed one-time-token page from the browser history instead of tracking a separate one-time-token MFA state.

Comment thread packages/experience/src/shared/components/NavBar/index.tsx Outdated
Comment thread packages/experience/src/pages/OneTimeToken/index.tsx Outdated
Comment thread packages/experience/src/Providers/UserInteractionContextProvider/index.tsx Outdated
Address PR review feedback by removing the sessionStorage flag and
isBackHidden plumbing. Instead, pass replace: true from the one-time
token page through useSubmitInteractionErrorHandler so profile and MFA
redirects remove the consumed token page from the browser history.

Also thread replace through useSendMfaVerificationCode for email/phone
MFA verification redirects from the one-time token flow.

Co-authored-by: wangsijie <sijiewg@gmail.com>
@github-actions github-actions Bot added size/s and removed size/m labels Jun 1, 2026
Copy link
Copy Markdown
Member

@charIeszhao charIeszhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The updated approach replaces the consumed one-time-token landing page in browser history and threads replace through the email/phone MFA verification redirect path, so the original back-navigation issue is addressed without the sessionStorage flag or per-page back hiding.

@wangsijie wangsijie merged commit 94108a0 into master Jun 2, 2026
38 of 59 checks passed
@wangsijie wangsijie deleted the sijie-hide-mfa-back-one-time-token-974a branch June 2, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

bug: MFA and oneTimeToken

5 participants