[PR #5826] [MERGED] fix(two-factor): improve error message for bad totp code in 2FA setup #31856

Closed
opened 2026-04-17 22:43:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5826
Author: @DevDuki
Created: 11/7/2025
Status: Merged
Merged: 11/8/2025
Merged by: @Bekacru

Base: canaryHead: fix/return-correct-error-for-bad-TOTP-code-in-2FA-setup


📝 Commits (3)

  • e0db612 fix: return correct error code for invalid totp code during setup
  • 47ab34b fix: missing 2fa cookie test
  • 0435b40 fix: use BASE_ERROR_CODES enum for invalid password

📊 Changes

3 files changed (+61 additions, -14 deletions)

View changed files

📝 packages/better-auth/src/plugins/two-factor/index.ts (+1 -1)
📝 packages/better-auth/src/plugins/two-factor/two-factor.test.ts (+52 -3)
📝 packages/better-auth/src/plugins/two-factor/verify-two-factor.ts (+8 -10)

📄 Description

fixes https://github.com/better-auth/better-auth/issues/2631


Summary by cubic

Return the correct error code for invalid TOTP during 2FA setup. Adds tests to verify missing two-factor cookie and invalid code behaviors.

  • Bug Fixes

    • Invalid TOTP now returns TWO_FACTOR_ERROR_CODES.INVALID_CODE.
    • Missing two-factor cookie returns INVALID_TWO_FACTOR_COOKIE and does not create a session.
  • Refactors

    • Centralized error handling via an invalid() helper for consistent UNAUTHORIZED responses.

Written for commit 0435b401fd. 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/5826 **Author:** [@DevDuki](https://github.com/DevDuki) **Created:** 11/7/2025 **Status:** ✅ Merged **Merged:** 11/8/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/return-correct-error-for-bad-TOTP-code-in-2FA-setup` --- ### 📝 Commits (3) - [`e0db612`](https://github.com/better-auth/better-auth/commit/e0db612cd3ae819510e771fe1558f25c6c0fa457) fix: return correct error code for invalid totp code during setup - [`47ab34b`](https://github.com/better-auth/better-auth/commit/47ab34b0970a5f36fb67b55bf477b5313af364eb) fix: missing 2fa cookie test - [`0435b40`](https://github.com/better-auth/better-auth/commit/0435b401fdfe97434ce705770fb087f66eb43f37) fix: use BASE_ERROR_CODES enum for invalid password ### 📊 Changes **3 files changed** (+61 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/two-factor/index.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/two-factor/two-factor.test.ts` (+52 -3) 📝 `packages/better-auth/src/plugins/two-factor/verify-two-factor.ts` (+8 -10) </details> ### 📄 Description fixes https://github.com/better-auth/better-auth/issues/2631 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Return the correct error code for invalid TOTP during 2FA setup. Adds tests to verify missing two-factor cookie and invalid code behaviors. - **Bug Fixes** - Invalid TOTP now returns TWO_FACTOR_ERROR_CODES.INVALID_CODE. - Missing two-factor cookie returns INVALID_TWO_FACTOR_COOKIE and does not create a session. - **Refactors** - Centralized error handling via an invalid() helper for consistent UNAUTHORIZED responses. <sup>Written for commit 0435b401fdfe97434ce705770fb087f66eb43f37. 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-04-17 22:43:56 -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#31856