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

  1. Wrap your driver in drizzle() before passing it: DrizzleAdapter(drizzle(postgres(url))).
  2. Deduplicate drizzle-orm so only one copy is installed (npm ls drizzle-orm; dedupe/overrides) — multiple copies break instanceof checks.
  3. Pass the correct instance for your dialect (PgDatabase, MySqlDatabase, BaseSQLiteDatabase).
  4. 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

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


AI-assisted analysis of nextauthjs/next-auth@a1a16a5a77 (2026-08-28). Data as JSON: /api/errors/322d12660b78e69e. Report an issue: GitHub.