[PR #8772] feat(two-factor): include enabled 2fa methods in sign-in redirect response #16451

Closed
opened 2026-04-13 10:31:37 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/8772

State: closed
Merged: Yes


closes #4101

when a user with 2fa signs in, the redirect response used to only return { twoFactorRedirect: true } with no way to know whether they had totp, otp, or both. frontends had to guess or do hacky workarounds to figure out which verification ui to show.

now the response includes twoFactorMethods (e.g. ["totp", "otp"]), and the onTwoFactorRedirect client callback receives it as a context param.


Summary by cubic

Include twoFactorMethods in the 2FA sign-in redirect and pass it to onTwoFactorRedirect so UIs can show the right flow. Methods are based on verified TOTP status and otpOptions.sendOTP, and exclude disabled or unverified providers.

  • New Features
    • twoFactor in better-auth now returns { twoFactorRedirect: true, twoFactorMethods: [...] }: adds "totp" only if the user has a verified TOTP secret and TOTP isn’t disabled; adds "otp" when otpOptions.sendOTP is set.
    • twoFactorClient calls onTwoFactorRedirect({ twoFactorMethods }). Docs updated; tests cover TOTP/OTP combinations, disabled-TOTP, and unverified-TOTP exclusion.

Written for commit 35356a2bc8. Summary will update on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/8772 **State:** closed **Merged:** Yes --- closes #4101 when a user with 2fa signs in, the redirect response used to only return `{ twoFactorRedirect: true }` with no way to know whether they had totp, otp, or both. frontends had to guess or do hacky workarounds to figure out which verification ui to show. now the response includes `twoFactorMethods` (e.g. `["totp", "otp"]`), and the `onTwoFactorRedirect` client callback receives it as a context param. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Include `twoFactorMethods` in the 2FA sign-in redirect and pass it to `onTwoFactorRedirect` so UIs can show the right flow. Methods are based on verified TOTP status and `otpOptions.sendOTP`, and exclude disabled or unverified providers. - New Features - `twoFactor` in `better-auth` now returns `{ twoFactorRedirect: true, twoFactorMethods: [...] }`: adds `"totp"` only if the user has a verified TOTP secret and TOTP isn’t disabled; adds `"otp"` when `otpOptions.sendOTP` is set. - `twoFactorClient` calls `onTwoFactorRedirect({ twoFactorMethods })`. Docs updated; tests cover TOTP/OTP combinations, disabled-TOTP, and unverified-TOTP exclusion. <sup>Written for commit 35356a2bc87f67c2a8cc9750534768e6c6630258. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 10:31:37 -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#16451