import { betterAuth } from 'better-auth' import { drizzleAdapter } from 'better-auth/adapters/drizzle' import { magicLink } from 'better-auth/plugins' import { db } from './db' import * as schema from './db/schema' import { sendEmail } from './email' export const auth = betterAuth({ logger: { level: 'debug' }, database: drizzleAdapter(db, { provider: 'pg', schema: { user: schema.user, session: schema.session, verification: schema.verification, }, }), // Disable password-based signup — invite-only, magic link only emailAndPassword: { enabled: false }, plugins: [ magicLink({ disableSignUp: true, // only existing (invited) users can sign in sendMagicLink: async ({ email, url }) => { await sendEmail({ to: email, subject: 'Sign in to MulliganMates', html: `
`, }) }, }), ], user: { additionalFields: { handicapIndex: { type: 'number', nullable: true, fieldName: 'handicap_index', }, }, }, }) export type Session = typeof auth.$Infer.Session