[PR #5329] feat(two-factor): add twoFactorPage config #5932

Open
opened 2026-03-13 12:41:48 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5329
Author: @wuzgood98
Created: 10/15/2025
Status: 🔄 Open

Base: canaryHead: feat/two-factor-add-two-factor-page-config


📝 Commits (4)

  • b19591c feat(two-factor): add twoFactorPage option to twoFactorClient plugin and its logic to handle redirecting users to the specified page when 2FA verification is required
  • 02f59b1 docs: update 2FA documentation to include usage of twoFactorPage configuration for redirecting users during verification
  • 9c7ae82 docs(2fa): add warning about full page reload when using twoFactorPage option and suggest onTwoFactorRedirect for smoother user experience
  • 768c462 refactor(two-factor): streamline redirect logic in twoFactorClient by prioritizing onTwoFactorRedirect and adding fallback to twoFactorPage

📊 Changes

2 files changed (+31 additions, -0 deletions)

View changed files

📝 docs/content/docs/plugins/2fa.mdx (+18 -0)
📝 packages/better-auth/src/plugins/two-factor/client.ts (+13 -0)

📄 Description

What changes were made and why:

  • Add the TypeScript options interface for twoFactorClient to accept twoFactorPage.
  • Add the logic to handle redirecting users to the specified page when 2FA verification is required and twoFactorPage is provided.
  • This ensures users do not encounter typescript errors when they use the example from the docs on the basic usage of Two Factor.
  • Users can either use twoFactorPage or onTwoFactorRedirect to redirect if a user needs to verify their two factor.

Relevant context:

  • Currently twoFactorClient does not accept twoFactorPage as an option.
  • The recommended option was to use onTwoFactorRedirect which was not used in the docs on its basic usage.

Breaking changes / depreciations:

  • No breaking changes.

Screenshots for UI changes:

  • No UI changes, but this snippet works now:
    Better-Auth-Two-Factor-client-plugin-basic-usage

Related issues / discussions:


Summary by cubic

Added a twoFactorPage option to twoFactorClient to redirect users to a 2FA page when verification is required, with onTwoFactorRedirect taking priority and twoFactorPage as a full-reload fallback. Docs add a warning and a usage example that compiles.

Written for commit 768c46212e02bee307fac78e3a3c3631603219fd. 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/5329 **Author:** [@wuzgood98](https://github.com/wuzgood98) **Created:** 10/15/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feat/two-factor-add-two-factor-page-config` --- ### 📝 Commits (4) - [`b19591c`](https://github.com/better-auth/better-auth/commit/b19591c949456d43963760ead2a776ecd51b846d) feat(two-factor): add `twoFactorPage` option to `twoFactorClient` plugin and its logic to handle redirecting users to the specified page when 2FA verification is required - [`02f59b1`](https://github.com/better-auth/better-auth/commit/02f59b1fab43c5f835b4a0a58d41c16187fd5038) docs: update 2FA documentation to include usage of `twoFactorPage` configuration for redirecting users during verification - [`9c7ae82`](https://github.com/better-auth/better-auth/commit/9c7ae82744c578a7e4374f8e245f948e9fcad35a) docs(2fa): add warning about full page reload when using `twoFactorPage` option and suggest `onTwoFactorRedirect` for smoother user experience - [`768c462`](https://github.com/better-auth/better-auth/commit/768c46212e02bee307fac78e3a3c3631603219fd) refactor(two-factor): streamline redirect logic in `twoFactorClient` by prioritizing `onTwoFactorRedirect` and adding fallback to `twoFactorPage` ### 📊 Changes **2 files changed** (+31 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/2fa.mdx` (+18 -0) 📝 `packages/better-auth/src/plugins/two-factor/client.ts` (+13 -0) </details> ### 📄 Description **What changes were made and why:** - Add the TypeScript options interface for `twoFactorClient` to accept `twoFactorPage`. - Add the logic to handle redirecting users to the specified page when 2FA verification is required and `twoFactorPage` is provided. - This ensures users do not encounter typescript errors when they use the example from the docs on the [basic usage](https://www.better-auth.com/docs/basic-usage#client-configuration) of Two Factor. - Users can either use `twoFactorPage` or `onTwoFactorRedirect` to redirect if a user needs to verify their two factor. **Relevant context:** - Currently `twoFactorClient` does not accept `twoFactorPage` as an option. - The recommended option was to use `onTwoFactorRedirect` which was not used in the docs on its basic usage. **Breaking changes / depreciations:** - No breaking changes. **Screenshots for UI changes:** - No UI changes, but this snippet works now: <img width="3680" height="1540" alt="Better-Auth-Two-Factor-client-plugin-basic-usage" src="https://github.com/user-attachments/assets/e2547759-ce9d-42b3-b01b-8e1b92c19037" /> **Related issues / discussions:** - Closes: #5326 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Added a twoFactorPage option to twoFactorClient to redirect users to a 2FA page when verification is required, with onTwoFactorRedirect taking priority and twoFactorPage as a full-reload fallback. Docs add a warning and a usage example that compiles. <sup>Written for commit 768c46212e02bee307fac78e3a3c3631603219fd. 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 12:41:48 -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#5932