57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { betterAuth } from 'better-auth';
|
|
import { prismaAdapter } from 'better-auth/adapters/prisma';
|
|
import { prisma } from '$lib/db';
|
|
import { sveltekitCookies } from 'better-auth/svelte-kit';
|
|
import { getRequestEvent } from '$app/server';
|
|
import { sendMail } from './server/resend';
|
|
import { sendVerificationEmail } from './server/email-verification';
|
|
import { env } from '$env/dynamic/private';
|
|
|
|
export const auth = betterAuth({
|
|
baseURL: env.BETTER_AUTH_URL,
|
|
database: prismaAdapter(prisma, {
|
|
provider: 'postgresql'
|
|
}),
|
|
emailVerification: {
|
|
sendOnSignUp: true,
|
|
sendVerificationEmail: async ({ user, token }) => {
|
|
void sendVerificationEmail({
|
|
email: user.email,
|
|
token
|
|
}).catch((e) => {
|
|
console.error('sendVerificationEmail template email failed:', e);
|
|
});
|
|
}
|
|
},
|
|
emailAndPassword: {
|
|
enabled: true,
|
|
requireEmailVerification: true,
|
|
sendResetPassword: async ({ user, url }) => {
|
|
void sendMail({
|
|
to: user.email,
|
|
templateId: 'password-reset-email',
|
|
data: {
|
|
target_email_address: user.email,
|
|
reset_link: url
|
|
}
|
|
}).catch((e) => {
|
|
console.error('sendResetPassword template email failed:', e);
|
|
});
|
|
}
|
|
},
|
|
socialProviders: {
|
|
google: {
|
|
prompt: 'select_account',
|
|
clientId: env.GOOGLE_CLIENT_ID as string,
|
|
clientSecret: env.GOOGLE_CLIENT_SECRET as string
|
|
}
|
|
},
|
|
rateLimit: {
|
|
enabled: true,
|
|
window: 60,
|
|
max: 100
|
|
},
|
|
trustedOrigins: ['http://localhost:5173', 'https://portal.rhemawavetech.com'],
|
|
plugins: [sveltekitCookies(getRequestEvent)]
|
|
});
|