import { wrapLayout } from '@/emails/booking-confirmation'; import { dash } from '@better-auth/infra'; import { betterAuth } from 'better-auth'; import { prismaAdapter } from 'better-auth/adapters/prisma'; import { openAPI } from 'better-auth/plugins'; import { sendMail } from './mailer'; import { db } from './prisma'; export const auth = betterAuth({ database: prismaAdapter(db, { provider: 'postgresql', }), secret: process.env.BETTER_AUTH_SECRET, baseURL: process.env.BETTER_AUTH_URL, session: { cookieCache: { enabled: false, }, }, emailAndPassword: { enabled: true, }, user: { additionalFields: { phone: { type: 'string', required: false, }, }, }, emailVerification: { sendOnSignUp: true, autoSignInAfterVerification: true, sendVerificationEmail: async ({ user, url }) => { const verificationUrl = new URL(url); const appUrl = process.env.APP_BASE_URL ?? 'http://localhost:5173'; verificationUrl.searchParams.set('callbackURL', appUrl); const content = `
Verificación de email

Verificá tu dirección de correo electrónico

Playzer Playzer
padding:0 20px 16px;

Hacé click en el botón de abajo para verificar tu dirección de correo electrónico y empezar a usar Playzer.

Verificar email

Si no creaste una cuenta en Playzer, ignorá este mensaje.

`; await sendMail({ to: user.email, subject: 'Verificá tu email en Playzer', html: wrapLayout(content), text: `Hacé click para verificar tu email: ${verificationUrl.toString()}`, }); }, }, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID!, clientSecret: process.env.GOOGLE_CLIENT_SECRET!, }, }, trustedOrigins: [ process.env.APP_BASE_URL ?? 'http://localhost:5173', process.env.BETTER_AUTH_URL ?? 'http://localhost:3000', ], plugins: [openAPI(), dash()], }); export type Session = typeof auth.$Infer.Session.session; export type User = typeof auth.$Infer.Session.user;