How to avoid singleton database when setting up better auth

from what I am seeing in the installation steps, the way to set this up is by making a specific file in an specific folder and exporting specifically an auth variable:
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@/db"; // your drizzle instance

export const auth = betterAuth({
    database: drizzleAdapter(db, {
        provider: "pg", // or "mysql", "sqlite"
    }),
});


I don't have a singleton database, so this is impossible for me. my database is setup a main function on startup, not exported.

someone else offered this solution in a different post, but it doesn't work:
// lib/auth.ts
export function initAuth(db: DB) {
  return betterAuth({
    database: drizzleAdapter(db, { provider: 'pg' })
  });
}

// index.ts
async function main() {
  ...

  const db = await openDB({ config: config.value });
  if (db.isErr()) {
    ...
  }

  const { runMigrations } = await getMigrations(initAuth(db.value) as BetterAuthOptions);
  await runMigrations();
  
  ...
}

await main();

I get this error:
2025-09-24T02:44:44.487Z WARN [Better Auth]: Could not determine database type, defaulting to sqlite. Please provide a type in the database options to avoid this.
2025-09-24T02:44:44.488Z ERROR [Better Auth]: Only kysely adapter is supported for migrations. You can use `generate` command to generate the schema, if you're using a different adapter.


nowhere in the docs seem to be explained why better auth needs to be initialised in this very specific way or what the consequences are for not doing so, either way I still like to inject my dependencies, is there any way to achieve this pattern?\
Was this page helpful?