Skip to content

Fix unhandled rejection when cancelling MFA setup after enable - #7665

Draft
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixmfa-catch-409-from-cancelmfasetup-on-2e3185
Draft

Fix unhandled rejection when cancelling MFA setup after enable#7665
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixmfa-catch-409-from-cancelmfasetup-on-2e3185

Conversation

@posthog-eu

@posthog-eu posthog-eu Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Description of Changes

Why: A user who finished two-factor setup in onboarding tripped a silent unhandled promise rejection that error tracking reports as Error: {"error":"MFA already enabled"}. The failure is benign for the user — setup completes and no toast shows — but it is noise in error tracking and a latent floating-rejection pattern in the desktop client.

Problem

  • The MFA onboarding slide cleanup cancels the pending setup on unmount when setupCompleteRef.current is false (MFASetupSlide.tsx).
  • That ref was synced from state in a separate effect, but handleEnableMfa flips the state and calls onMfaSetupComplete?.() in the same tick.
  • If the parent unmounts the slide before the sync effect commits, the cleanup cancels a setup where MFA is already enabled; the backend answers HTTP 409.
  • The void discarded the promise, so nothing caught the rejection and autocapture picked it up. On desktop the body is wrapped into an Error by TauriHttpClient.createError.

Changes

  • Set setupCompleteRef.current = true directly when enable succeeds, so the cleanup skips the cancel without waiting for a follow-up effect to commit.
  • Settle the cancel promise with .catch(), so a 409 is a no-op rather than a floating rejection. This mirrors the try/catch already used in AccountSection.tsx.
  • Remove the now-redundant effect that mirrored state into the ref.

Treating a 409 as a no-op is correct: once MFA is enabled there is no pending secret left to clear.


Checklist

General

Documentation

Translations (if applicable)

UI Changes (if applicable)

  • Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR)

Testing (if applicable)

  • I have run task check to verify linters, typechecks, and tests pass
  • I have tested my changes locally. Refer to the Testing Guide for more details.

Created with PostHog Desktop from this inbox report.

The MFA onboarding slide runs a cleanup on unmount that cancels the
pending MFA setup when setup is not complete. The completion flag lived
in a ref that a separate effect synced from state, so an unmount in the
same tick as enable could fire the cancel against an account that already
has MFA enabled. The backend answers HTTP 409 and the discarded promise
surfaced as an unhandled rejection in error tracking.

Set the completion ref directly when enable succeeds, and settle the
cancel promise so a 409 is a no-op rather than a floating rejection.
This mirrors the try/catch already used in AccountSection.

Generated-By: PostHog Desktop
Task-Id: ef5a2561-fb31-4999-bd01-f6614fd03dd3
@github-actions github-actions Bot added the Front End Issues or pull requests related to front-end development label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Front End Issues or pull requests related to front-end development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants