[PR #7243] [MERGED] fix(two-factor): allow passwordless 2FA management #32769

Closed
opened 2026-04-17 23:30:35 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7243
Author: @gustavovalverde
Created: 1/10/2026
Status: Merged
Merged: 3/30/2026
Merged by: @gustavovalverde

Base: mainHead: feat/two-factor-passwordless-canary


📝 Commits (2)

  • 4fc867a feat(two-factor): allow passwordless 2FA management
  • 21e2fe1 Merge branch 'main' into feat/two-factor-passwordless-canary

📊 Changes

7 files changed (+314 additions, -66 deletions)

View changed files

📝 docs/content/docs/plugins/2fa.mdx (+13 -11)
📝 packages/better-auth/src/plugins/two-factor/backup-codes/index.ts (+33 -8)
📝 packages/better-auth/src/plugins/two-factor/index.ts (+85 -40)
📝 packages/better-auth/src/plugins/two-factor/totp/index.ts (+29 -7)
📝 packages/better-auth/src/plugins/two-factor/two-factor.test.ts (+130 -0)
📝 packages/better-auth/src/plugins/two-factor/types.ts (+7 -0)
📝 packages/better-auth/src/utils/password.ts (+17 -0)

📄 Description

Summary

  • add allowPasswordless to two-factor management so passwordless users can enable/disable 2FA, fetch TOTP URIs, and regenerate backup codes
  • preserve the password requirement for users with credential accounts
  • expand tests for passwordless flows and update docs to list supported passwordless methods explicitly

Rationale

Passwordless sign-in methods (passkeys, magic links, email OTP, OAuth/social, anonymous) cannot provide a password, but they still benefit from 2FA. This change enables 2FA management for those users while maintaining the existing password gate for credential accounts.


Summary by cubic

Adds passwordless 2FA management so users without a credential (password) account can enable/disable 2FA, fetch TOTP URIs, and regenerate backup codes without a password. Credential users still must provide a password; default behavior is unchanged.

  • New Features

    • Added allowPasswordless to twoFactor, TOTP, and backup codes (default false); top-level option cascades to sub-features unless overridden.
    • Request bodies accept an optional password when allowed for: enableTwoFactor, disableTwoFactor, getTOTPURI, generateBackupCodes.
    • New shouldRequirePassword utility checks for a credential account and enforces password when needed.
    • Updated docs to reflect optional passwords for passwordless users; added tests for anonymous flows and credential enforcement.
  • Migration

    • No changes needed by default.
    • To enable for passwordless users: twoFactor({ allowPasswordless: true }) or set per-feature options.
    • Clients may omit password only for users without a credential account; keep sending password for credential users.

Written for commit 21e2fe1ad5. Summary will update 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/7243 **Author:** [@gustavovalverde](https://github.com/gustavovalverde) **Created:** 1/10/2026 **Status:** ✅ Merged **Merged:** 3/30/2026 **Merged by:** [@gustavovalverde](https://github.com/gustavovalverde) **Base:** `main` ← **Head:** `feat/two-factor-passwordless-canary` --- ### 📝 Commits (2) - [`4fc867a`](https://github.com/better-auth/better-auth/commit/4fc867aa55c8542dbf52c23814f6280bffe13321) feat(two-factor): allow passwordless 2FA management - [`21e2fe1`](https://github.com/better-auth/better-auth/commit/21e2fe1ad52e697b6cf788995701b1cca099a05a) Merge branch 'main' into feat/two-factor-passwordless-canary ### 📊 Changes **7 files changed** (+314 additions, -66 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/2fa.mdx` (+13 -11) 📝 `packages/better-auth/src/plugins/two-factor/backup-codes/index.ts` (+33 -8) 📝 `packages/better-auth/src/plugins/two-factor/index.ts` (+85 -40) 📝 `packages/better-auth/src/plugins/two-factor/totp/index.ts` (+29 -7) 📝 `packages/better-auth/src/plugins/two-factor/two-factor.test.ts` (+130 -0) 📝 `packages/better-auth/src/plugins/two-factor/types.ts` (+7 -0) 📝 `packages/better-auth/src/utils/password.ts` (+17 -0) </details> ### 📄 Description ## Summary - add `allowPasswordless` to two-factor management so passwordless users can enable/disable 2FA, fetch TOTP URIs, and regenerate backup codes - preserve the password requirement for users with credential accounts - expand tests for passwordless flows and update docs to list supported passwordless methods explicitly ## Rationale Passwordless sign-in methods (passkeys, magic links, email OTP, OAuth/social, anonymous) cannot provide a password, but they still benefit from 2FA. This change enables 2FA management for those users while maintaining the existing password gate for credential accounts. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds passwordless 2FA management so users without a credential (password) account can enable/disable 2FA, fetch TOTP URIs, and regenerate backup codes without a password. Credential users still must provide a password; default behavior is unchanged. - New Features - Added `allowPasswordless` to `twoFactor`, TOTP, and backup codes (default false); top-level option cascades to sub-features unless overridden. - Request bodies accept an optional `password` when allowed for: `enableTwoFactor`, `disableTwoFactor`, `getTOTPURI`, `generateBackupCodes`. - New `shouldRequirePassword` utility checks for a credential account and enforces password when needed. - Updated docs to reflect optional passwords for passwordless users; added tests for anonymous flows and credential enforcement. - Migration - No changes needed by default. - To enable for passwordless users: `twoFactor({ allowPasswordless: true })` or set per-feature options. - Clients may omit password only for users without a credential account; keep sending password for credential users. <sup>Written for commit 21e2fe1ad52e697b6cf788995701b1cca099a05a. Summary will update 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 23:30:35 -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#32769