import { betterAuth } from 'better-auth'; import { organization, magicLink } from 'better-auth/plugins'; import { passkey } from '@better-auth/passkey'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; import { db } from '@/db'; import * as schema from '@/db/schema'; const baseURL = process.env.BETTER_AUTH_URL || 'http://localhost:3001'; export const auth = betterAuth({ baseURL, database: drizzleAdapter(db, { provider: 'pg', schema, }), emailAndPassword: { enabled: true, }, plugins: [ organization(), passkey({ rpID: new URL(baseURL).hostname, rpName: 'Bagsy', origin: baseURL, }), magicLink({ sendMagicLink: async ({ email, url }) => { console.log(`Magic link for ${email}: ${url}`); }, }), ], trustedOrigins: [ baseURL, 'bagsy://', 'bagsy://localhost', 'http://localhost:3001', 'http://192.168.*:3001', ], });