Integrations

Tokens for apps and services

Bearer tokens for native apps, and JWTs for other services.

Two of Better Auth's plugins, for clients that can't use the session cookie.

nuxt.config.ts
export default defineNuxtConfig({
  betterAuthUi: {
    bearer: true,
    jwt: true
  }
})

Bearer tokens

For native apps, other servers, and signed-in devices. Every sign-in returns the session token in a set-auth-token response header. Send it back as Authorization: Bearer <token>, and Better Auth treats it as the session:

server/api/me.get.ts
export default defineEventHandler(async (event) => {
  // Works with the cookie or the Authorization header.
  const session = await serverAuth(event).api.getSession({ headers: event.headers })
  return session?.user
})

bearer: { requireSignature: true } accepts only signed tokens. No migration needed.

Better Auth advises using bearer tokens only for clients that can't use cookies.

JWTs

For other services that need to know who's signed in, without asking your app. GET /api/auth/token (or the set-auth-jwt header on get-session) gives a short-lived JWT with the user in its payload. Services verify it with your public keys at /api/auth/jwks, which the admin's configuration page shows.

nuxt.config.ts
export default defineNuxtConfig({
  betterAuthUi: {
    jwt: {
      expirationTime: '15m'
    }
  }
})
issuer
string
Who issues the tokens. Defaults to your app's base URL.
audience
string
Who the tokens are for. Defaults to your app's base URL.
expirationTime
stringdefault: '15m'
How long a token lasts, for example '15m' or '1h'.
jwksPath
stringdefault: '/jwks'
Where the public keys are, under Better Auth's base path.

Run Better Auth's migrations after turning it on: it adds a jwks table.

A JWT isn't a replacement for the session, as Better Auth says: use it for services, not for your own pages.