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).
- Analysis: Reads
pluginsfrom your config. - Generation: Generates a Drizzle schema file corresponding to your database dialect (SQLite, PostgreSQL, MySQL).
- 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)postgresqlmysql
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):
- Update
server/auth.config.ts. - Restart your development server.
- The module regenerates the schema.
- If using NuxtHub local development, the tables are ready.
- Deploy with migrations:
For local development, migrations run automatically when you start the dev server.
For production (Cloudflare D1):npx nuxt db migrate
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.