Files
LabWise/server/src/auth/auth.ts

66 lines
1.7 KiB
TypeScript
Raw Normal View History

import { betterAuth } from 'better-auth';
import { kyselyAdapter } from '@better-auth/kysely-adapter';
import { Kysely, PostgresDialect } from 'kysely';
import { Pool } from 'pg';
2026-03-19 19:59:01 -05:00
import { sendEmail, verificationEmailHtml, resetPasswordEmailHtml } from './email';
const db = new Kysely({
dialect: new PostgresDialect({
pool: new Pool({
2026-03-19 19:59:01 -05:00
connectionString:
process.env.DATABASE_URL ||
'postgresql://labwise:labwise_dev_pw@localhost:5432/labwise_db',
}),
}),
});
export const auth = betterAuth({
database: kyselyAdapter(db, { type: 'postgres' }),
baseURL: process.env.BETTER_AUTH_URL || 'http://localhost:3001',
2026-03-19 19:59:01 -05:00
secret:
process.env.BETTER_AUTH_SECRET ||
'dev-secret-change-in-production-min32chars!!',
rateLimit: {
enabled: false, // TODO: re-enable in production
},
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
sendResetPassword: async ({ user, url }) => {
await sendEmail({
to: user.email,
subject: 'Reset your LabWise password',
html: resetPasswordEmailHtml(url),
});
},
},
emailVerification: {
sendVerificationEmail: async ({ user, url }) => {
await sendEmail({
to: user.email,
subject: 'Verify your LabWise email',
html: verificationEmailHtml(url),
});
},
},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID || '',
clientSecret: process.env.GOOGLE_CLIENT_SECRET || '',
},
},
trustedOrigins: [
'http://localhost:5173',
'https://labwise.wahwa.com',
2026-03-20 00:02:56 -05:00
// iOS native app callback — allows Better Auth to honour the
// https://labwise.wahwa.com/api/ios-callback callbackURL
'labwise://',
],
});