36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { betterAuth } from 'better-auth'
|
|
import Database from 'better-sqlite3'
|
|
import { organization, jwt } from 'better-auth/plugins'
|
|
import { resend } from './mail'
|
|
|
|
export const auth = betterAuth({
|
|
database: new Database('./sqlite.db'),
|
|
emailAndPassword: { enabled: true, autoSignIn: false },
|
|
plugins: [
|
|
jwt({
|
|
jwt: {
|
|
issuer: 'http://192.168.178.114:3001',
|
|
expirationTime: '48h'
|
|
},
|
|
jwks: {
|
|
keyPairConfig: {
|
|
// Supported by NimbusJwtDecoder
|
|
alg: 'ES512'
|
|
}
|
|
}
|
|
}),
|
|
organization({
|
|
async sendInvitationEmail(data) {
|
|
console.log('Sending invitation email', data)
|
|
const inviteLink = `http://192.168.178.114:3001/accept-invitation/${data.id}`
|
|
await resend.emails.send({
|
|
from: 'Acme <onboarding@resend.dev>',
|
|
to: data.email,
|
|
subject: 'Email Verification',
|
|
html: `You are invited to the Organization ${data.organization.name}! Click the link to verify your email: ${inviteLink}`
|
|
})
|
|
}
|
|
})
|
|
]
|
|
})
|