[GH-ISSUE #2903] oneTimeToken forces session auth as middleware #9387

Closed
opened 2026-04-13 04:49:47 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @fl0wo on GitHub (Jun 4, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2903

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Hi, I'd like to be able to use OTT plugin without session middleware (because for some reason i'm getting 401 UNAUTHORIZED) even tho I'm passing my own middleware auth logic.

export const oneTimeToken = (options?: OneTimeTokenOptions) => {
	return {
		id: "one-time-token",
		endpoints: {
			generateOneTimeToken: createAuthEndpoint(
				"/one-time-token/generate",
				{
					method: "GET",
					use: [sessionMiddleware], // <--- ability to customize this/remove
				},
[wrangler:inf] GET /v0/ott/token 200 OK (1582ms)
⎔ Reloading local server...
c.req.header() {
  accept: '*/*',
  'accept-encoding': 'br, gzip',
  'cf-connecting-ip': '::1',
  host: 'localhost:8787',
  'my-api-key': 'aaa',
  'my-org-id': 'bbb'
}
✘ [ERROR] Error generating one-time token: [APIError] {
    status: 'UNAUTHORIZED',
    body: undefined,
    headers: {},
    statusCode: 401
  }

Thank you.

Current vs. Expected behavior

.

What version of Better Auth are you using?

latest

Provide environment information

.

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
   oneTimeToken()
});

Additional context

No response

Originally created by @fl0wo on GitHub (Jun 4, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2903 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Hi, I'd like to be able to use OTT plugin without session middleware (because for some reason i'm getting 401 UNAUTHORIZED) even tho I'm passing my own middleware auth logic. ``` export const oneTimeToken = (options?: OneTimeTokenOptions) => { return { id: "one-time-token", endpoints: { generateOneTimeToken: createAuthEndpoint( "/one-time-token/generate", { method: "GET", use: [sessionMiddleware], // <--- ability to customize this/remove }, ``` ``` [wrangler:inf] GET /v0/ott/token 200 OK (1582ms) ⎔ Reloading local server... c.req.header() { accept: '*/*', 'accept-encoding': 'br, gzip', 'cf-connecting-ip': '::1', host: 'localhost:8787', 'my-api-key': 'aaa', 'my-org-id': 'bbb' } ✘ [ERROR] Error generating one-time token: [APIError] { status: 'UNAUTHORIZED', body: undefined, headers: {}, statusCode: 401 } ``` Thank you. ### Current vs. Expected behavior . ### What version of Better Auth are you using? latest ### Provide environment information ```bash . ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ oneTimeToken() }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 04:49:47 -05:00
Author
Owner

@rj-elias commented on GitHub (Jul 31, 2025):

OTT doesn't work either for me. I get 401 UNAUTHORIZED

<!-- gh-comment-id:3139239161 --> @rj-elias commented on GitHub (Jul 31, 2025): OTT doesn't work either for me. I get `401 UNAUTHORIZED`
Author
Owner

@ping-maxwell commented on GitHub (Oct 2, 2025):

This is done because when you verify an OTT it returns the session attached to the initially generated token.

If you want to just have a verification system of a given token then I recommend the api-key plugin.

<!-- gh-comment-id:3359371580 --> @ping-maxwell commented on GitHub (Oct 2, 2025): This is done because when you verify an OTT it returns the session attached to the initially generated token. If you want to just have a verification system of a given token then I recommend the api-key plugin.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9387