[PR #6604] [MERGED] fix: delete 2FA verification token after successful TOTP verification #6775

Closed
opened 2026-03-13 13:11:20 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6604
Author: @delfortrie
Created: 12/8/2025
Status: Merged
Merged: 12/9/2025
Merged by: @Bekacru

Base: canaryHead: fix/delete-2fa-verification-token


📝 Commits (2)

  • 1803c01 fix: delete 2FA verification token after successful TOTP verification
  • 420b79a fix: update test to start new 2FA session for invalid backup code check

📊 Changes

2 files changed (+29 additions, -5 deletions)

View changed files

📝 packages/better-auth/src/plugins/two-factor/two-factor.test.ts (+21 -1)
📝 packages/better-auth/src/plugins/two-factor/verify-two-factor.ts (+8 -4)

📄 Description

Delete the verification token from the database after successful 2FA verification to prevent token accumulation and table bloat.

Also moves the two-factor cookie cleanup outside of the trustDevice conditional so it always gets cleared after successful verification.

This aligns with the fix in #6194 for passkey challenges.


Summary by cubic

Delete 2FA verification tokens after successful TOTP verification and always clear the two-factor cookie to prevent database bloat and leftover auth state.

  • Bug Fixes
    • Delete the verification token on successful 2FA verification to stop token accumulation.
    • Clear the two-factor cookie regardless of trustDevice, aligning with the passkey fix in #6194.

Written for commit 420b79a58e. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6604 **Author:** [@delfortrie](https://github.com/delfortrie) **Created:** 12/8/2025 **Status:** ✅ Merged **Merged:** 12/9/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/delete-2fa-verification-token` --- ### 📝 Commits (2) - [`1803c01`](https://github.com/better-auth/better-auth/commit/1803c01bd4bf8e6df2d8900060b042f370f6de0b) fix: delete 2FA verification token after successful TOTP verification - [`420b79a`](https://github.com/better-auth/better-auth/commit/420b79a58ede83f883a0e413ffebed4fccb8969e) fix: update test to start new 2FA session for invalid backup code check ### 📊 Changes **2 files changed** (+29 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/two-factor/two-factor.test.ts` (+21 -1) 📝 `packages/better-auth/src/plugins/two-factor/verify-two-factor.ts` (+8 -4) </details> ### 📄 Description Delete the verification token from the database after successful 2FA verification to prevent token accumulation and table bloat. Also moves the two-factor cookie cleanup outside of the trustDevice conditional so it always gets cleared after successful verification. This aligns with the fix in #6194 for passkey challenges. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Delete 2FA verification tokens after successful TOTP verification and always clear the two-factor cookie to prevent database bloat and leftover auth state. - **Bug Fixes** - Delete the verification token on successful 2FA verification to stop token accumulation. - Clear the two-factor cookie regardless of trustDevice, aligning with the passkey fix in #6194. <sup>Written for commit 420b79a58ede83f883a0e413ffebed4fccb8969e. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:11:20 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6775