[GH-ISSUE #8119] 2fa/magic-link in oauth2 flows needs documentation #11000

Open
opened 2026-04-13 07:22:46 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @till on GitHub (Feb 23, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8119

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Enable 2fa on an account and then try to complete an oauth2 flow.

Current vs. Expected behavior

I am using better-auth in an application written in Hono, so most/all my calls are on the backend.

Currently, most backend methods require me to inject oauth_query to keep the state, but these functions are different and don't handle it at all:

  • auth.api.verifyTOTP
  • auth.api.verifyBackupCode
  • auth.api.signInMagicLink
  • auth.api.magicLinkVerify

Injecting the oauth_query (via body) yields an API Error (e.g. for 2fa) or it gets silently ignored (magic-link), so I have to handle the redirect to consent manually.

What version of Better Auth are you using?

1.5.0-beta.16

System info

├── @better-auth/cli@1.5.0-beta.13
├── @better-auth/oauth-provider@1.5.0-beta.16
├── better-auth@1.5.0-beta.16

Which area(s) are affected? (Select all that apply)

Other

Auth config (if applicable)


Additional context

I've made it work with the following:

+      if (oauth_query) {
+        // Strip prompt=login — the user just re-authenticated via 2FA
+        const params = new URLSearchParams(oauth_query);
+        params.delete("prompt");
+        return c.redirect(`/api/auth/oauth2/authorize?${params}`);
+      }
Originally created by @till on GitHub (Feb 23, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8119 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Enable 2fa on an account and then try to complete an oauth2 flow. ### Current vs. Expected behavior I am using better-auth in an application written in Hono, so most/all my calls are on the backend. Currently, most backend methods require me to inject `oauth_query` to keep the state, but these functions are different and don't handle it at all: - `auth.api.verifyTOTP` - `auth.api.verifyBackupCode` - `auth.api.signInMagicLink` - `auth.api.magicLinkVerify` Injecting the `oauth_query` (via body) yields an API Error (e.g. for 2fa) or it gets silently ignored (magic-link), so I have to handle the redirect to consent manually. ### What version of Better Auth are you using? 1.5.0-beta.16 ### System info ```bash ├── @better-auth/cli@1.5.0-beta.13 ├── @better-auth/oauth-provider@1.5.0-beta.16 ├── better-auth@1.5.0-beta.16 ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript ``` ### Additional context I've made it work with the following: ```diff + if (oauth_query) { + // Strip prompt=login — the user just re-authenticated via 2FA + const params = new URLSearchParams(oauth_query); + params.delete("prompt"); + return c.redirect(`/api/auth/oauth2/authorize?${params}`); + } ```
GiteaMirror added the docs label 2026-04-13 07:22:46 -05:00
Author
Owner

@till commented on GitHub (Feb 24, 2026):

For magic-link, you have to set the callbackURL to an absolue URI.

<!-- gh-comment-id:3951891496 --> @till commented on GitHub (Feb 24, 2026): For magic-link, you have to set the `callbackURL` to an absolue URI.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#11000