2026-01-25 16:21:00 +00:00
|
|
|
import { betterAuth } from "better-auth"
|
2026-03-16 01:30:02 +00:00
|
|
|
import { drizzleAdapter } from "better-auth/adapters/drizzle"
|
2026-03-16 22:39:40 +00:00
|
|
|
import { admin } from "better-auth/plugins"
|
2026-01-25 16:21:00 +00:00
|
|
|
|
2026-03-16 01:30:02 +00:00
|
|
|
import type { Database } from "../db/index.ts"
|
2026-03-16 22:39:40 +00:00
|
|
|
|
2026-03-16 01:30:02 +00:00
|
|
|
import * as schema from "../db/schema.ts"
|
2026-01-25 16:21:00 +00:00
|
|
|
|
2026-03-16 01:30:02 +00:00
|
|
|
export function createAuth(db: Database) {
|
2026-03-16 22:39:40 +00:00
|
|
|
if (!process.env.BETTER_AUTH_SECRET) {
|
|
|
|
|
throw new Error("BETTER_AUTH_SECRET is not set")
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 01:30:02 +00:00
|
|
|
return betterAuth({
|
|
|
|
|
database: drizzleAdapter(db, {
|
|
|
|
|
provider: "pg",
|
|
|
|
|
schema,
|
|
|
|
|
}),
|
2026-03-23 00:31:23 +00:00
|
|
|
advanced: {
|
|
|
|
|
disableCSRFCheck: process.env.NODE_ENV !== "production",
|
|
|
|
|
},
|
2026-03-16 01:30:02 +00:00
|
|
|
emailAndPassword: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
},
|
2026-03-16 22:39:40 +00:00
|
|
|
plugins: [admin()],
|
2026-03-16 01:30:02 +00:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type Auth = ReturnType<typeof createAuth>
|