35 lines
961 B
TypeScript
35 lines
961 B
TypeScript
import { betterAuth } from 'better-auth'
|
|
import { prismaAdapter } from 'better-auth/adapters/prisma'
|
|
import { magicLink } from 'better-auth/plugins'
|
|
import { admin as adminPlugin } from 'better-auth/plugins'
|
|
import { prisma } from '@innungsapp/shared'
|
|
import { sendMagicLinkEmail } from './email'
|
|
|
|
export const auth = betterAuth({
|
|
database: prismaAdapter(prisma, {
|
|
provider: 'postgresql',
|
|
}),
|
|
secret: process.env.BETTER_AUTH_SECRET!,
|
|
baseURL: process.env.BETTER_AUTH_URL!,
|
|
trustedOrigins: [
|
|
process.env.NEXT_PUBLIC_APP_URL ?? 'http://localhost:3000',
|
|
process.env.EXPO_PUBLIC_API_URL ?? 'http://localhost:3000',
|
|
],
|
|
plugins: [
|
|
magicLink({
|
|
sendMagicLink: async ({ email, url }) => {
|
|
await sendMagicLinkEmail({ to: email, magicUrl: url })
|
|
},
|
|
}),
|
|
adminPlugin(),
|
|
],
|
|
session: {
|
|
cookieCache: {
|
|
enabled: true,
|
|
maxAge: 60 * 5, // 5 minutes cache
|
|
},
|
|
},
|
|
})
|
|
|
|
export type Auth = typeof auth
|