mirror of
https://github.com/kennethnym/aris.git
synced 2026-06-15 20:11:18 +01:00
40 lines
897 B
TypeScript
40 lines
897 B
TypeScript
import { betterAuth } from "better-auth"
|
|
import { drizzleAdapter } from "better-auth/adapters/drizzle"
|
|
import { admin } from "better-auth/plugins"
|
|
|
|
import type { Database } from "../db/index.ts"
|
|
|
|
import * as schema from "../db/schema.ts"
|
|
import { insertDefaultUserSources } from "../sources/default-sources.ts"
|
|
|
|
export function createAuth(db: Database) {
|
|
if (!process.env.BETTER_AUTH_SECRET) {
|
|
throw new Error("BETTER_AUTH_SECRET is not set")
|
|
}
|
|
|
|
return betterAuth({
|
|
database: drizzleAdapter(db, {
|
|
provider: "pg",
|
|
schema,
|
|
}),
|
|
advanced: {
|
|
disableCSRFCheck: process.env.NODE_ENV !== "production",
|
|
},
|
|
emailAndPassword: {
|
|
enabled: true,
|
|
},
|
|
databaseHooks: {
|
|
user: {
|
|
create: {
|
|
async after(user, _context) {
|
|
await insertDefaultUserSources(db, user.id)
|
|
},
|
|
},
|
|
},
|
|
},
|
|
plugins: [admin()],
|
|
})
|
|
}
|
|
|
|
export type Auth = ReturnType<typeof createAuth>
|