[PR #5329] [MERGED] feat(two-factor): add twoFactorPage in config #31533

Closed
opened 2026-04-17 22:25:50 -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: Merged
Merged: 3/16/2026
Merged by: @himself65

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


📝 Commits (4)

  • ea505d0 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
  • b521198 docs: update 2FA documentation to include usage of twoFactorPage configuration for redirecting users during verification
  • 37ffc6d docs(2fa): add warning about full page reload when using twoFactorPage option and suggest onTwoFactorRedirect for smoother user experience
  • 4e4b875 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 prioritized and twoFactorPage used as a full-page reload fallback. Docs add a usage example and a warning about the reload.

Written for commit 4e4b875315. 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/5329 **Author:** [@wuzgood98](https://github.com/wuzgood98) **Created:** 10/15/2025 **Status:** ✅ Merged **Merged:** 3/16/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `feat/two-factor-add-two-factor-page-config` --- ### 📝 Commits (4) - [`ea505d0`](https://github.com/better-auth/better-auth/commit/ea505d0f0f47c57f0edf7303b2a3c68a858877e8) 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 - [`b521198`](https://github.com/better-auth/better-auth/commit/b521198c0a8cc2ee06d41541b7dfe6381038f074) docs: update 2FA documentation to include usage of `twoFactorPage` configuration for redirecting users during verification - [`37ffc6d`](https://github.com/better-auth/better-auth/commit/37ffc6d0496cac556cb4ffb0255184e75eaec2f8) docs(2fa): add warning about full page reload when using `twoFactorPage` option and suggest `onTwoFactorRedirect` for smoother user experience - [`4e4b875`](https://github.com/better-auth/better-auth/commit/4e4b8753156865b1ac8982bd1b1786b8fbee83c3) 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 prioritized and twoFactorPage used as a full-page reload fallback. Docs add a usage example and a warning about the reload. <sup>Written for commit 4e4b8753156865b1ac8982bd1b1786b8fbee83c3. 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 22:25:51 -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#31533