Skip to content

Commit 1723e27

Browse files
committed
fix(account): prevent duplicate TOTP submission toast on success
Clear code input immediately after successful TOTP binding to prevent the auto-submit useEffect from triggering a duplicate API call. The issue occurred because: 1. User enters 6 digits, triggering handleSubmit via useEffect 2. API call succeeds, loading changes from true to false 3. handleSubmit (which depends on loading) gets recreated 4. useEffect triggers again since handleSubmit is a dependency 5. Second API call returns "TOTP is already in use" error toast By clearing codeInput before navigation, the isCodeReady check fails and prevents the duplicate submission.
1 parent 3f71959 commit 1723e27

File tree

1 file changed

+4
-0
lines changed
  • packages/account/src/pages/TotpBinding

1 file changed

+4
-0
lines changed

packages/account/src/pages/TotpBinding/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ const TotpBinding = () => {
144144
return;
145145
}
146146

147+
// Clear code input to prevent duplicate submission from the auto-submit useEffect
148+
// (when loading state changes, handleSubmit gets recreated, which triggers the effect again)
149+
setCodeInput([]);
150+
147151
if (isBackupCodeEnabled(experienceSettings?.mfa) && !hasBackupCodes) {
148152
void navigate(backupCodesGenerateRoute, { replace: true });
149153
return;

0 commit comments

Comments
 (0)