mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2026-09-03 05:10:16 +03:00
Fix unhandled rejection when cancelling MFA setup after enable
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 commit is contained in:
@@ -73,16 +73,14 @@ function MFASetupContent({ onMfaSetupComplete }: MFASetupSlideProps) {
|
||||
}
|
||||
}, [t]);
|
||||
|
||||
useEffect(() => {
|
||||
setupCompleteRef.current = setupComplete;
|
||||
}, [setupComplete]);
|
||||
|
||||
useEffect(() => {
|
||||
void fetchMfaSetup();
|
||||
|
||||
return () => {
|
||||
if (!setupCompleteRef.current) {
|
||||
void accountService.cancelMfaSetup();
|
||||
accountService.cancelMfaSetup().catch(() => {
|
||||
// No pending secret to clear once MFA is enabled; ignore the 409.
|
||||
});
|
||||
}
|
||||
};
|
||||
}, [fetchMfaSetup]);
|
||||
@@ -113,6 +111,7 @@ function MFASetupContent({ onMfaSetupComplete }: MFASetupSlideProps) {
|
||||
setSubmitting(true);
|
||||
setMfaError("");
|
||||
await accountService.enableMfa(mfaSetupCode.trim());
|
||||
setupCompleteRef.current = true;
|
||||
setSetupComplete(true);
|
||||
onMfaSetupComplete?.();
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user