Skip to content

Conversation

@wangsijie
Copy link
Contributor

Summary

  • Fixed duplicate "TOTP is already in use" toast appearing after successful TOTP binding

Root Cause

When user enters 6 digits for TOTP verification:

  1. The auto-submit useEffect triggers handleSubmit
  2. API call succeeds and loading state changes from true to false
  3. Since handleSubmit depends on loading, it gets recreated (new function reference)
  4. The useEffect triggers again because handleSubmit is in its dependency array
  5. With codeInput still containing 6 digits, isCodeReady() returns true
  6. A second API call is made, which returns "TOTP is already in use" error

Solution

Clear codeInput immediately after successful TOTP binding, before navigation. This causes isCodeReady(codeInput) to return false when the effect re-triggers, preventing the duplicate submission.

Test plan

  • Bind TOTP authenticator app in account center
  • Verify only success page shows without "TOTP is already in use" toast

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.
@github-actions
Copy link

COMPARE TO master

Total Size Diff 📈 +214 Bytes

Diff by File
Name Diff
packages/account/src/pages/TotpBinding/index.tsx 📈 +214 Bytes

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.

2 participants