Database provider type is undefined during Drizzle schema generation #2945

Open
opened 2026-03-13 10:29:12 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @jan10 on GitHub (Mar 1, 2026).

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Use a monorepo (pnpm workspaces) with Better Auth config in a package (e.g. packages/auth/auth.ts) like https://github.com/t3-oss/create-t3-turbo
  2. Configure the Drizzle adapter with provider: "pg" as documented:
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@xxxx/db/db";

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
  }),
  // ... other options, plugins
});
  1. Run from the package: npx auth generate --adapter drizzle
  2. The CLI loads the config (dotenv injects env, config is found) but then throws:
⠋ preparing schema...file:///Users/jan/.npm/_npx/cec068fea869db4d/node_modules/auth/dist/generators-YiCQyoNc.mjs:22
if (!databaseType) throw new Error(`Database provider type is undefined during Drizzle schema generation. Please define a \`provider\` in the Drizzle adapter config. Read more at https://better-auth.com/docs/adapters/drizzle`);
                         ^

Error: Database provider type is undefined during Drizzle schema generation. Please define a `provider` in the Drizzle adapter config. Read more at https://better-auth.com/docs/adapters/drizzle
    at generateDrizzleSchema (...)
    at generateSchema (...)
    at Command.generateAction (...)

Current vs. Expected behavior

  • Current: The generator reports that the database provider type is undefined and asks to define provider in the Drizzle adapter config, even though provider: "pg" is already set in drizzleAdapter(db, { provider: "pg" }).
  • Expected: With provider: "pg" (or "sqlite" / "mysql") in the adapter options, npx auth generate --adapter drizzle should succeed and emit the Drizzle schema (or use the provider when generating from the loaded config).

So the bug is that the CLI’s schema generator does not see the provider value that is passed into drizzleAdapter(..., { provider: "pg" }) when it introspects the loaded config. The adapter’s return value likely does not expose the options (e.g. provider) on the object the generator reads.

What version of Better Auth are you using?

1.5.0

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@xxxx/db/db"; // Drizzle instance from @neondatabase/serverless + drizzle-orm

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
  }),
  baseURL: process.env.BETTER_AUTH_URL,
  // ... emailAndPassword, plugins (organization, admin, scim, apiKey, passkey, emailOTP, i18n, etc.)
});


No wrapper or `Object.assign` around the adapter; config matches the docs. The same error occurs when running `npx auth generate` without `--adapter drizzle` (config is loaded, then generation fails with the same message).

Additional context

No response

Originally created by @jan10 on GitHub (Mar 1, 2026). Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Use a monorepo (pnpm workspaces) with Better Auth config in a package (e.g. `packages/auth/auth.ts`) like https://github.com/t3-oss/create-t3-turbo 2. Configure the Drizzle adapter with `provider: "pg"` as [documented](https://better-auth.com/docs/adapters/drizzle): ```ts import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@xxxx/db/db"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", }), // ... other options, plugins }); ``` 3. Run from the package: `npx auth generate --adapter drizzle` 4. The CLI loads the config (dotenv injects env, config is found) but then throws: ``` ⠋ preparing schema...file:///Users/jan/.npm/_npx/cec068fea869db4d/node_modules/auth/dist/generators-YiCQyoNc.mjs:22 if (!databaseType) throw new Error(`Database provider type is undefined during Drizzle schema generation. Please define a \`provider\` in the Drizzle adapter config. Read more at https://better-auth.com/docs/adapters/drizzle`); ^ Error: Database provider type is undefined during Drizzle schema generation. Please define a `provider` in the Drizzle adapter config. Read more at https://better-auth.com/docs/adapters/drizzle at generateDrizzleSchema (...) at generateSchema (...) at Command.generateAction (...) ``` ### Current vs. Expected behavior - **Current:** The generator reports that the database provider type is undefined and asks to define `provider` in the Drizzle adapter config, even though `provider: "pg"` is already set in `drizzleAdapter(db, { provider: "pg" })`. - **Expected:** With `provider: "pg"` (or `"sqlite"` / `"mysql"`) in the adapter options, `npx auth generate --adapter drizzle` should succeed and emit the Drizzle schema (or use the provider when generating from the loaded config). So the bug is that the CLI’s schema generator does not see the `provider` value that is passed into `drizzleAdapter(..., { provider: "pg" })` when it introspects the loaded config. The adapter’s return value likely does not expose the options (e.g. `provider`) on the object the generator reads. ### What version of Better Auth are you using? 1.5.0 ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@xxxx/db/db"; // Drizzle instance from @neondatabase/serverless + drizzle-orm export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", }), baseURL: process.env.BETTER_AUTH_URL, // ... emailAndPassword, plugins (organization, admin, scim, apiKey, passkey, emailOTP, i18n, etc.) }); No wrapper or `Object.assign` around the adapter; config matches the docs. The same error occurs when running `npx auth generate` without `--adapter drizzle` (config is loaded, then generation fails with the same message). ``` ### Additional context _No response_
GiteaMirror added the adapter label 2026-03-13 10:29:12 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 1, 2026):

Hi @jan10! I'm Dosu and I’m helping the better-auth team.

This is a known issue. The most likely cause is that you're missing the schema parameter in your drizzleAdapter config. Without it, the adapter doesn't properly initialize and expose the provider option to the CLI.

Try adding your schema:

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@xxxx/db/db";
import * as schema from "@xxxx/db/schema"; // Import your schema

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
    schema, // Add this
  }),
});

Alternatively, pass the schema when creating your Drizzle instance:

export const db = drizzle(client, { schema });

If that doesn't work, also check:

  1. TypeScript path aliases - The CLI uses jiti which doesn't resolve path aliases. Use relative imports instead of ~db or @/db.
  2. CLI version - Versions 1.3.5+ have Zod issues. Try npx @better-auth/cli@1.3.4 generate or install Zod as a dev dependency.

The underlying issue is that the CLI reads adapter.options?.provider, but the adapter factory chain only fully exposes these options when schema is provided during initialization.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Mar 1, 2026): <!-- Greeting --> Hi @jan10! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known issue. The most likely cause is that you're **missing the `schema` parameter** in your drizzleAdapter config. Without it, the adapter doesn't properly initialize and expose the `provider` option to the CLI. Try adding your schema: ```typescript import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@xxxx/db/db"; import * as schema from "@xxxx/db/schema"; // Import your schema export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schema, // Add this }), }); ``` Alternatively, pass the schema when creating your Drizzle instance: ```typescript export const db = drizzle(client, { schema }); ``` If that doesn't work, also check: 1. **TypeScript path aliases** - The CLI uses `jiti` which [doesn't resolve path aliases](https://github.com/better-auth/better-auth/issues/6373). Use relative imports instead of `~db` or `@/db`. 2. **CLI version** - [Versions 1.3.5+ have Zod issues](https://github.com/better-auth/better-auth/issues/3951). Try `npx @better-auth/cli@1.3.4 generate` or install Zod as a dev dependency. The underlying issue is that the [CLI reads `adapter.options?.provider`](https://github.com/better-auth/better-auth/blob/977bfa602f4085acec44eb53659e1db1d78a73da/packages/cli/src/generators/drizzle.ts#L27-L28), but the adapter factory chain only fully exposes these options when schema is provided during initialization. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/bd43f312-5d8a-4574-9855-3e0beef2cc74?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/bd43f312-5d8a-4574-9855-3e0beef2cc74?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/bd43f312-5d8a-4574-9855-3e0beef2cc74?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/bd43f312-5d8a-4574-9855-3e0beef2cc74?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/bd43f312-5d8a-4574-9855-3e0beef2cc74?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/bd43f312-5d8a-4574-9855-3e0beef2cc74?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/bd43f312-5d8a-4574-9855-3e0beef2cc74?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20known%20issue.%20The%20most%20likely%20cause%20is%20that%20you%27re%20%2A%2Amissing%20the%20%60schema%60%20parameter%2A%2A%20in%20your%20drizzleAdapter%20config.%20Without%20it%2C%20the%20adapter%20doesn%27t%20properly%20initialize%20and%20expose%20the%20%60provider%60%20option%20to%20the%20CLI.%0A%0ATry%20adding%20your%20schema%3A%0A%0A%60%60%60typescript%0Aimport%20%7B%20betterAuth%20%7D%20from%20%22better-auth%22%3B%0Aimport%20%7B%20drizzleAdapter%20%7D%20from%20%22better-auth/adapters/drizzle%22%3B%0Aimport%20%7B%20db%20%7D%20from%20%22%40xxxx/db/db%22%3B%0Aimport%20%2A%20as%20schema%20from%20%22%40xxxx/db/schema%22%3B%20//%20Import%20your%20schema%0A%0Aexport%20const%20auth%20%3D%20betterAuth%28%7B%0A%20%20database%3A%20drizzleAdapter%28db%2C%20%7B%0A%20%20%20%20provider%3A%20%22pg%22%2C%0A%20%20%20%20schema%2C%20//%20Add%20this%0A%20%20%7D%29%2C%0A%7D%29%3B%0A%60%60%60%0A%0AAlternatively%2C%20pass%20the%20schema%20when%20creating%20your%20Drizzle%20instance%3A%0A%0A%60%60%60typescript%0Aexport%20const%20db%20%3D%20drizzle%28client%2C%20%7B%20schema%20%7D%29%3B%0A%60%60%60%0A%0AIf%20that%20doesn%27t%20work%2C%20also%20check%3A%0A1.%20%2A%2ATypeScript%20path%20aliases%2A%2A%20-%20The%20CLI%20uses%20%60jiti%60%20which%20%5Bdoesn%27t%20resolve%20path%20aliases%5D%28https%3A//github.com/better-auth/better-auth/issues/6373%29.%20Use%20relative%20imports%20instead%20of%20%60~db%60%20or%20%60%40/db%60.%0A2.%20%2A%2ACLI%20version%2A%2A%20-%20%5BVersions%201.3.5%2B%20have%20Zod%20issues%5D%28https%3A//github.com/better-auth/better-auth/issues/3951%29.%20Try%20%60npx%20%40better-auth/cli%401.3.4%20generate%60%20or%20install%20Zod%20as%20a%20dev%20dependency.%0A%0AThe%20underlying%20issue%20is%20that%20the%20%5BCLI%20reads%20%60adapter.options%3F.provider%60%5D%28https%3A//github.com/better-auth/better-auth/blob/977bfa602f4085acec44eb53659e1db1d78a73da/packages/cli/src/generators/drizzle.ts%23L27-L28%29%2C%20but%20the%20adapter%20factory%20chain%20only%20fully%20exposes%20these%20options%20when%20schema%20is%20provided%20during%20initialization.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/8256)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2945