nextauthjs/next-auth · error
Unsupported database type (${typeof db}) in Auth.js Drizzle
Error message
Unsupported database type (${typeof db}) in Auth.js Drizzle adapter. What it means
DrizzleAdapter accepts a driver-agnostic drizzle instance and uses instanceof checks (is(db, PgDatabase), BaseSQLiteDatabase, etc.) to dispatch to the right dialect-specific adapter. If the passed object matches none of the known database classes, it throws this error. The typeof db in the message shows the JS type of what you actually passed, which is the main debugging clue.
Source
Thrown at packages/adapter-drizzle/src/index.ts:42
import { DefaultPostgresSchema, PostgresDrizzleAdapter } from "./lib/pg.js"
import { DefaultSQLiteSchema, SQLiteDrizzleAdapter } from "./lib/sqlite.js"
import { DefaultSchema, SqlFlavorOptions } from "./lib/utils.js"
import type { Adapter } from "@auth/core/adapters"
export function DrizzleAdapter<SqlFlavor extends SqlFlavorOptions>(
db: SqlFlavor,
schema?: DefaultSchema<SqlFlavor>
): Adapter {
if (is(db, MySqlDatabase)) {
return MySqlDrizzleAdapter(db, schema as DefaultMySqlSchema)
} else if (is(db, PgDatabase)) {
return PostgresDrizzleAdapter(db, schema as DefaultPostgresSchema)
} else if (is(db, BaseSQLiteDatabase)) {
return SQLiteDrizzleAdapter(db, schema as DefaultSQLiteSchema)
}
throw new Error(
`Unsupported database type (${typeof db}) in Auth.js Drizzle adapter.`
)
}
View on GitHub (pinned to a1a16a5a77)
Solutions
- Wrap your driver in drizzle() before passing it: DrizzleAdapter(drizzle(postgres(url))).
- Deduplicate drizzle-orm so only one copy is installed (npm ls drizzle-orm; dedupe/overrides) — multiple copies break instanceof checks.
- Pass the correct instance for your dialect (PgDatabase, MySqlDatabase, BaseSQLiteDatabase).
- Check the typeof value in the error message; 'string' means you passed the connection URL directly.
Example fix
// before
const adapter = DrizzleAdapter('postgres://user:pass@localhost/db')
// after
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
const adapter = DrizzleAdapter(drizzle(postgres('postgres://user:pass@localhost/db'))) Defensive patterns
Strategy: type-guard
Validate before calling
import { is } from 'drizzle-orm'
import { PgDatabase } from 'drizzle-orm/pg-core'
if (!is(db, PgDatabase)) throw new Error('DrizzleAdapter requires a drizzle() database instance') Type guard
function isDrizzleDb(db: unknown): db is PgDatabase {
return is(db, PgDatabase)
} Try / catch
try {
const adapter = DrizzleAdapter(db)
} catch (e) {
if (e instanceof Error && e.message.includes('Unsupported database type')) {
// typeof in message tells you what you passed; wrap driver in drizzle() or dedupe drizzle-orm
}
throw e
} Prevention
- Always wrap raw drivers with drizzle() before passing to DrizzleAdapter
- Ensure a single drizzle-orm version (npm ls drizzle-orm; dedupe)
- Read the typeof in the error message to diagnose what was actually passed
- Match the adapter import to your dialect (pg-core, mysql-core, sqlite-core)
When it happens
Trigger: Passing something that is not a drizzle database instance: a plain connection string, a raw driver client (e.g. mysql2 pool, postgres.js sql), a Neon/HTTP client not wrapped in drizzle, or an incompatible drizzle version where instanceof checks fail.
Common situations: Forgetting to wrap the driver with drizzle() (e.g. passing postgres(sql) instead of drizzle(sql)), duplicating drizzle-orm versions so instanceof fails across package instances, or passing a mysql2 connection directly.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- Dgraph client error: Please provide an API key
- Dgraph client error: Please provide a valid GraphQL endpoint
- No user id.
- No user found.
- Authenticator not found.
AI-assisted analysis of nextauthjs/next-auth@a1a16a5a77 (2026-08-28).
Data as JSON: /api/errors/322d12660b78e69e.
Report an issue: GitHub.