Fix unhandled rejection when cancelling MFA setup after enable - #7665
Draft
posthog-eu[bot] wants to merge 1 commit into
Draft
Fix unhandled rejection when cancelling MFA setup after enable#7665posthog-eu[bot] wants to merge 1 commit into
posthog-eu[bot] wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
setupCompleteRef.currentis false (MFASetupSlide.tsx).handleEnableMfaflips the state and callsonMfaSetupComplete?.()in the same tick.voiddiscarded the promise, so nothing caught the rejection and autocapture picked it up. On desktop the body is wrapped into anErrorbyTauriHttpClient.createError.Changes
setupCompleteRef.current = truedirectly when enable succeeds, so the cleanup skips the cancel without waiting for a follow-up effect to commit..catch(), so a 409 is a no-op rather than a floating rejection. This mirrors the try/catch already used inAccountSection.tsx.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)
scripts/counter_translation.pyUI Changes (if applicable)
Testing (if applicable)
task checkto verify linters, typechecks, and tests passCreated with PostHog Desktop from this inbox report.