63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import { betterAuth } from 'better-auth'
|
|
import { prismaAdapter } from 'better-auth/adapters/prisma'
|
|
import { passkey } from '@better-auth/passkey'
|
|
import { organization } from 'better-auth/plugins/organization'
|
|
import { prisma } from './db'
|
|
import { emailProvider } from './lib/email'
|
|
|
|
export const auth = betterAuth({
|
|
appName: 'Gruperly',
|
|
database: prismaAdapter(prisma, {
|
|
provider: 'postgresql',
|
|
}),
|
|
emailAndPassword: {
|
|
enabled: true,
|
|
minPasswordLength: 8,
|
|
sendResetPassword: async ({ user, url }) => {
|
|
await emailProvider.sendPasswordResetEmail({
|
|
email: user.email,
|
|
url,
|
|
name: user.name,
|
|
})
|
|
},
|
|
},
|
|
emailVerification: {
|
|
sendOnSignUp: true,
|
|
sendOnSignIn: true,
|
|
autoSignInAfterVerification: true,
|
|
sendVerificationEmail: async ({ user, token }) => {
|
|
const webUrl = process.env.WEB_URL ?? 'http://localhost:6173'
|
|
const verificationUrl = new URL('/verify-email', webUrl)
|
|
verificationUrl.searchParams.set('token', token)
|
|
await emailProvider.sendVerificationEmail({
|
|
email: user.email,
|
|
url: verificationUrl.toString(),
|
|
name: user.name,
|
|
})
|
|
},
|
|
},
|
|
socialProviders: {
|
|
...(process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET
|
|
? {
|
|
google: {
|
|
clientId: process.env.GOOGLE_CLIENT_ID,
|
|
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
},
|
|
}
|
|
: {}),
|
|
},
|
|
plugins: [
|
|
organization({
|
|
acronym: 'GRP',
|
|
allowUserToCreateOrganization: true,
|
|
organizationLimit: 10,
|
|
}),
|
|
passkey({
|
|
rpName: 'Gruperly',
|
|
}),
|
|
],
|
|
trustedOrigins: [
|
|
process.env.BETTER_AUTH_URL ?? 'http://localhost:4000',
|
|
process.env.WEB_URL ?? 'http://localhost:6173',
|
|
],
|
|
}) |