Core Concepts

`serverAuth()`

How the server Better Auth instance is created.

serverAuth() is auto‑imported on the server. It:

  • Calls your defineServerAuth function from server/auth.config.ts.
  • Injects the Drizzle adapter, secret, and baseURL.
  • Caches the instance for the lifetime of the server.
const auth = serverAuth()
const session = await auth.api.getSession({ headers: event.headers })

You rarely need to call it directly unless you’re building custom server logic.

See also