41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
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: 'sqlite',
|
|
}),
|
|
emailAndPassword: {
|
|
enabled: true,
|
|
},
|
|
secret: process.env.BETTER_AUTH_SECRET!,
|
|
baseURL: process.env.BETTER_AUTH_URL!,
|
|
trustedOrigins: [
|
|
process.env.NEXT_PUBLIC_APP_URL ?? 'http://localhost:3032',
|
|
process.env.EXPO_PUBLIC_API_URL ?? 'http://localhost:3032',
|
|
'http://192.168.178.115:3032',
|
|
'http://localhost:8081', // Expo dev client
|
|
'http://192.168.178.115:8081',
|
|
],
|
|
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
|