Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

wuzgood98
Copy link

@wuzgood98 wuzgood98 commented Oct 15, 2025

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 config to twoFactorClient to automatically redirect users to a 2FA verification page when needed. onTwoFactorRedirect remains supported as a fallback, and docs were updated so the basic usage example works without TypeScript errors.

…gin and its logic to handle redirecting users to the specified page when 2FA verification is required
…nfiguration for redirecting users during verification
Copy link

vercel bot commented Oct 15, 2025

@wuzgood98 is attempting to deploy a commit to the better-auth Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

pkg-pr-new bot commented Oct 15, 2025

Open in StackBlitz

better-auth

npm i https://pkg.pr.new/better-auth/better-auth@5329

@better-auth/cli

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/cli@5329

@better-auth/core

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/core@5329

@better-auth/expo

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/expo@5329

@better-auth/sso

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/sso@5329

@better-auth/stripe

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/stripe@5329

@better-auth/telemetry

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/telemetry@5329

commit: cc1856a

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

if (context.data?.twoFactorRedirect) {
if (options?.twoFactorPage) {
if (typeof window !== "undefined" && window.location) {
window.location.href = options.twoFactorPage;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue here is that it causes a full page reload. In frameworks like NextJS for instance, it may be more desirable to use Next's own router.push() instead.

The current method of setting onSuccess at the point of calling signIn on the client supports this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion! I understand your concern about full page reload. However, I have decided to keep the implementation as a fallback rather than use Next.js's router.push() for one reason:

  • Since Better-Auth is framework-agnostic and supports many environments, hardcoding Next.js's router will create a dependency on a specific framework, which would either require duplicate logic for each framework or force all users to implement framework-specific workarounds.

My Implementation:

  • onTwoFactorRedirect takes priority (so framework-specific routing works perfectly)
  • twoFactorPage serves as a simple fallback with a clear @warning that it causes a full page reload
    This gives users flexibility while maintaining the library's framework-agnostic design

Users who want smooth client-side navigation get it through the callback, while those who need a quick fallback have twoFactorPage.

…urs after custom callback execution, with added warning in documentation
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

…ge` option and suggest `onTwoFactorRedirect` for smoother user experience
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@Bekacru Bekacru added this to the 1.4.x milestone Oct 15, 2025
@Bekacru Bekacru enabled auto-merge October 17, 2025 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add twoFactorPage option to twoFactorClient plugin

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.