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.
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.