Reusing an existing Kysely connection in better-auth

Is it fine to just reuse the Postgres Pool in both Kysely and better-auth?

// use this in kysely and better-auth
export const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
});

export const db = new Kysely<Database>({
  dialect: PostgresDialect({
    pool,
  }),
});

export const auth = betterAuth({
  secret: process.env.BETTER_AUTH_SECRET!,
  database: pool,
  emailAndPassword: {
    enabled: true,
  },
  // nextcookies must be the last plugin in the array
  plugins: [nextCookies()],
});
Solution
Hey, Better-Auth supports using a Kysely instance.
So instead of passing your Pool, you can just pass your db:
ONrLzt7.png
Was this page helpful?