Skip to content

feat: 2fa backup codes#9

Open
akshayutture-augment wants to merge 1 commit into
enhance-two-factor-security-foundationfrom
improve-two-factor-authentication-features
Open

feat: 2fa backup codes#9
akshayutture-augment wants to merge 1 commit into
enhance-two-factor-security-foundationfrom
improve-two-factor-authentication-features

Conversation

@akshayutture-augment

@akshayutture-augment akshayutture-augment commented Nov 14, 2025

Copy link
Copy Markdown

Test 3


Replicated from ai-code-review-evaluation/cal.com-cursor#3


Note

Introduce 2FA backup codes with UI, API, auth, and DB changes to generate, use, and manage codes during login and 2FA enable/disable.

  • Auth/UI:
    • Add BackupCode input component and integrate into login and disable-2FA flows with a "lost access" toggle.
    • Enhance TwoFactor component with optional autoFocus prop.
    • Update enable-2FA modal to display generated backup codes, and provide copy/download/close actions.
    • Use PasswordField in relevant modals; minor accessibility tweak (toggle button tabIndex=-1).
  • Backend/API:
    • POST /api/auth/two-factor/totp/setup: generate 10 encrypted backup codes; return them with QR/secret; persist to user.
    • POST /api/auth/two-factor/totp/disable: accept backupCode as alternative to TOTP; validate; clear backupCodes on success; improved error handling.
    • TwoFactorAuthAPI.disable now sends { password, code, backupCode }.
  • Authentication (NextAuth):
    • Credentials provider accepts backupCode; decrypts/validates; invalidates used code; expanded error codes.
  • Database:
    • Add users.backupCodes column (encrypted JSON) via migration; update Prisma schema.
  • i18n:
    • Add strings for backup codes, errors, and related UI text.
  • Tests:
    • Extend 2FA e2e to verify backup code UI (download/copy) during enable flow.

Written by Cursor Bugbot for commit a308075. Configure here.

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
@akshayutture-augment

Copy link
Copy Markdown
Author

cursor review

setPassword("");
setErrorMessage(null);
setStep(SetupStep.ConfirmPassword);
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Memory Leak: Unrevoked Blob URLs

The resetState function doesn't revoke the blob URL stored in backupCodesUrl, causing a memory leak. When the modal closes or resets, the blob URL created on line 99 remains in memory. The cleanup should call URL.revokeObjectURL(backupCodesUrl) before resetting state, and ideally also in a cleanup effect when the component unmounts.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants