Getting Started

Server Configuration

Create `server/auth.config.ts` with your Better Auth setup.

The module requires a Better Auth config file at server/auth.config.ts.
It must export a default function created with defineServerAuth.

Example

import { admin } from 'better-auth/plugins'
import { defineServerAuth } from '@onmax/nuxt-better-auth'

export default defineServerAuth(({ db, runtimeConfig }) => ({
  appName: 'My App',

  // Any Better Auth options except database/secret/baseURL
  emailAndPassword: { enabled: true },
  plugins: [admin()],
}))

What the module adds

At runtime, serverAuth() wraps your config and injects:

  • database: Drizzle adapter for NuxtHub hub:db
  • secret: runtimeConfig.betterAuthSecret
  • baseURL: runtimeConfig.public.siteUrl

So you should not set those in your config.

Required runtime config

Make sure your app defines:

  • runtimeConfig.betterAuthSecret (commonly via BETTER_AUTH_SECRET)
  • runtimeConfig.public.siteUrl (commonly via NUXT_PUBLIC_SITE_URL)

See also