This library is in early development. Expect breaking changes.
Getting Started

Schema Generation

Auto-generate Drizzle ORM schemas for Better Auth tables when using NuxtHub.
Prompt
Set up auto schema generation for @onmax/nuxt-better-auth with NuxtHub.

- Requires NuxtHub integration — the module generates Drizzle ORM schemas at build time
- Supports sqlite (default), postgresql, and mysql dialects via `hub.db.dialect` in `nuxt.config.ts`
- The module reads `server/auth.config.ts` plugins to determine required tables (user, session, account, verification + plugin tables)
- After adding/removing plugins: restart the dev server to regenerate schemas
- For production (Cloudflare D1): run `npx nuxt db migrate`
- No manual Drizzle schema writing needed for auth tables

Read more: https://better-auth.nuxt.dev/raw/getting-started/schema-generation.md
Source: https://github.com/nuxt-modules/better-auth
This feature requires NuxtHub. See NuxtHub Integration for setup.

Better Auth requires tables for users, sessions, accounts. This module creates them automatically with NuxtHub and Drizzle ORM.

How it works

The module analyzes your server/auth.config.ts at build time to determine which tables are required by your core configuration and enabled plugins (e.g., twoFactor, passkey).

  1. Analysis: Reads plugins from your config.
  2. Generation: Generates a Drizzle schema file corresponding to your database dialect (SQLite, PostgreSQL, MySQL).
  3. Integration: Automatically injects this schema into NuxtHub's database configuration.
You do not need to manually write Drizzle schemas for authentication tables.

Supported Dialects

The module supports all dialects compatible with NuxtHub:

  • sqlite (Default)
  • postgresql
  • mysql

Ensure you have configured the dialect in nuxt.config.ts:

nuxt.config.ts
export default defineNuxtConfig({
  hub: {
    db: {
      dialect: 'postgresql' // or 'sqlite', 'mysql'
    }
  }
})

Workflow

When you add a new plugin that requires database tables (e.g., adding twoFactor):

  1. Update server/auth.config.ts.
  2. Restart your development server.
  3. The module regenerates the schema.
  4. If using NuxtHub local development, the tables are ready.
  5. Deploy with migrations:
    For local development, migrations run automatically when you start the dev server.
    For production (Cloudflare D1):
    npx nuxt db migrate
    
    See NuxtHub deployment documentation.
Restart Required: Because schema generation happens at build/module-setup time, you must restart the dev server after adding or removing plugins that affect the database structure.