Files
test/src/auth/auth.ts
T

40 lines
1.1 KiB
TypeScript

import { betterAuth } from 'better-auth';
import { prismaAdapter } from 'better-auth/adapters/prisma';
import { PrismaClient } from '@prisma/client';
import { admin } from 'better-auth/plugins';
import { applyFileCleanup } from '../prisma/file-cleanup.helper';
import { config } from '../shared/config/config';
const prisma = new PrismaClient();
applyFileCleanup(prisma);
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: 'postgresql',
}),
plugins: [admin()],
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
sendResetPassword: async ({ user, token }) => {
console.log(`Send reset password email to ${user.email}: ${token}`);
},
},
emailVerification: {
sendVerificationEmail: async ({ user, token }) => {
console.log(`Send verification email to ${user.email}: ${token}`);
},
sendOnSignIn: true,
autoSignInAfterVerification: true,
},
trustedOrigins: config.trustedOrigins,
socialProviders: {
google: {
prompt: 'select_account',
clientId: config.googleClientId,
clientSecret: config.googleClientSecret,
},
},
});