[PR #1281] [CLOSED] Feat/2fa email otp support #11978

Closed
opened 2026-04-13 08:06:06 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/1281
Author: @helloworld9912
Created: 1/25/2025
Status: Closed

Base: v1.3Head: feat/2fa-email-otp-support


📝 Commits (10+)

  • 799a04f feat(2FA): add email OTP verification support for 2FA operations
  • ee1007d feat(2FA): add email OTP support for backup code generation
  • 1d070b1 refactor(2FA): update client types for verification methods
  • 6255efb feat(2FA): add error codes for email OTP verification
  • 6593c50 feat(2FA): add email OTP support for TOTP URI generation
  • 311bede test(2FA): add email OTP verification test cases
  • d585a28 feat(types): add email verification types for 2FA plugin
  • bc3e6f8 Update docs
  • 8abbef2 make options inline
  • 4ac7e0a Update types.ts

📊 Changes

8 files changed (+512 additions, -123 deletions)

View changed files

📝 docs/content/docs/plugins/2fa.mdx (+55 -7)
📝 packages/better-auth/src/plugins/two-factor/backup-codes/index.ts (+69 -33)
📝 packages/better-auth/src/plugins/two-factor/client.ts (+48 -36)
📝 packages/better-auth/src/plugins/two-factor/error-code.ts (+5 -0)
📝 packages/better-auth/src/plugins/two-factor/index.ts (+138 -33)
📝 packages/better-auth/src/plugins/two-factor/totp/index.ts (+30 -6)
📝 packages/better-auth/src/plugins/two-factor/two-factor.test.ts (+155 -8)
📝 packages/better-auth/src/plugins/two-factor/types.ts (+12 -0)

📄 Description

Add Email OTP Verification Support for 2FA Operations

Overview

This PR adds support for email OTP verification across all Two-Factor Authentication operations, making 2FA more accessible for users who authenticate through social login providers or prefer email verification.

Key Changes

  • Added unified verification schema supporting both password and email OTP methods
  • Implemented email OTP verification for:
    • Enabling/disabling 2FA
    • Generating backup codes
    • Retrieving TOTP URI
  • Added comprehensive error handling for OTP verification scenarios
  • Enhanced TypeScript types for better type safety and developer experience
  • Added extensive test coverage for email OTP verification flows

Implementation Details

  • Created twoFactorVerificationSchema for consistent verification across endpoints
  • Added sendVerificationOTP handler in plugin configuration
  • Implemented proper OTP validation with expiration checks
  • Added logging for verification attempts to aid debugging
  • Updated API documentation to reflect new verification methods

Testing

  • Added test cases for all email OTP verification scenarios
  • Verified compatibility with existing password-based verification
  • Tested error handling and edge cases
  • Verified social login user flows

Checklist

  • Added TypeScript types
  • Added test coverage
  • Updated error messages
  • Added logging
  • Tested with social login flows
  • Maintained backward compatibility
  • Updated docs

🔄 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/1281 **Author:** [@helloworld9912](https://github.com/helloworld9912) **Created:** 1/25/2025 **Status:** ❌ Closed **Base:** `v1.3` ← **Head:** `feat/2fa-email-otp-support` --- ### 📝 Commits (10+) - [`799a04f`](https://github.com/better-auth/better-auth/commit/799a04fada6cce401870fe5a18f78268ccda2294) feat(2FA): add email OTP verification support for 2FA operations - [`ee1007d`](https://github.com/better-auth/better-auth/commit/ee1007d9d8935956cfead9e37ee89cd7a1665b02) feat(2FA): add email OTP support for backup code generation - [`1d070b1`](https://github.com/better-auth/better-auth/commit/1d070b12218a2e5c9828e2894e2321fb3ecb06d7) refactor(2FA): update client types for verification methods - [`6255efb`](https://github.com/better-auth/better-auth/commit/6255efbbaa3fc4e70469bfad363d41784ed5dfae) feat(2FA): add error codes for email OTP verification - [`6593c50`](https://github.com/better-auth/better-auth/commit/6593c50209fedf6ffaaa46d7995267cd4eb3f19f) feat(2FA): add email OTP support for TOTP URI generation - [`311bede`](https://github.com/better-auth/better-auth/commit/311bedee4e45023555a227cd95a3811644cd8532) test(2FA): add email OTP verification test cases - [`d585a28`](https://github.com/better-auth/better-auth/commit/d585a28dbca243fb5e9d56b91cb041617e16bcd5) feat(types): add email verification types for 2FA plugin - [`bc3e6f8`](https://github.com/better-auth/better-auth/commit/bc3e6f8320f1c5437fea9f3927258bab75cacb6c) Update docs - [`8abbef2`](https://github.com/better-auth/better-auth/commit/8abbef25b33bae82078566ab796099b44a4f92d0) make options inline - [`4ac7e0a`](https://github.com/better-auth/better-auth/commit/4ac7e0afaea342ebc7a2196faff672d28bbb1829) Update types.ts ### 📊 Changes **8 files changed** (+512 additions, -123 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/2fa.mdx` (+55 -7) 📝 `packages/better-auth/src/plugins/two-factor/backup-codes/index.ts` (+69 -33) 📝 `packages/better-auth/src/plugins/two-factor/client.ts` (+48 -36) 📝 `packages/better-auth/src/plugins/two-factor/error-code.ts` (+5 -0) 📝 `packages/better-auth/src/plugins/two-factor/index.ts` (+138 -33) 📝 `packages/better-auth/src/plugins/two-factor/totp/index.ts` (+30 -6) 📝 `packages/better-auth/src/plugins/two-factor/two-factor.test.ts` (+155 -8) 📝 `packages/better-auth/src/plugins/two-factor/types.ts` (+12 -0) </details> ### 📄 Description # Add Email OTP Verification Support for 2FA Operations ## Overview This PR adds support for email OTP verification across all Two-Factor Authentication operations, making 2FA more accessible for users who authenticate through social login providers or prefer email verification. ## Key Changes - Added unified verification schema supporting both password and email OTP methods - Implemented email OTP verification for: - Enabling/disabling 2FA - Generating backup codes - Retrieving TOTP URI - Added comprehensive error handling for OTP verification scenarios - Enhanced TypeScript types for better type safety and developer experience - Added extensive test coverage for email OTP verification flows ## Implementation Details - Created `twoFactorVerificationSchema` for consistent verification across endpoints - Added `sendVerificationOTP` handler in plugin configuration - Implemented proper OTP validation with expiration checks - Added logging for verification attempts to aid debugging - Updated API documentation to reflect new verification methods ## Testing - Added test cases for all email OTP verification scenarios - Verified compatibility with existing password-based verification - Tested error handling and edge cases - Verified social login user flows ## Related - Plugin configuration documentation will be updated in a separate PR - Fixes #1279 ## Checklist - [x] Added TypeScript types - [x] Added test coverage - [x] Updated error messages - [x] Added logging - [x] Tested with social login flows - [x] Maintained backward compatibility - [x] Updated docs --- <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-13 08:06:06 -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#11978