index.ts36 lines, 905 B
| 1 | import { betterAuth } from "better-auth"; |
| 2 | import { prismaAdapter } from "better-auth/adapters/prisma"; |
| 3 | import { db } from "../db"; |
| 4 | |
| 5 | export const auth = betterAuth({ |
| 6 | database: prismaAdapter(db, { |
| 7 | provider: "postgresql", // or "mysql", "postgresql", ...etc |
| 8 | }), |
| 9 | emailAndPassword: { |
| 10 | enabled: true, |
| 11 | }, |
| 12 | socialProviders: { |
| 13 | github: { |
| 14 | clientId: process.env.GITHUB_CLIENT_ID!, |
| 15 | clientSecret: process.env.GITHUB_CLIENT_SECRET!, |
| 16 | scope: ["read:user", "user:email", "repo"], |
| 17 | }, |
| 18 | }, |
| 19 | account: { |
| 20 | accountLinking: { |
| 21 | enabled: true, |
| 22 | trustedProviders: ["github"], |
| 23 | }, |
| 24 | }, |
| 25 | session: { |
| 26 | expiresIn: 60 * 60 * 24 * 7, // 7 days |
| 27 | updateAge: 60 * 60 * 24, // 24 hours |
| 28 | cookieCache: { |
| 29 | enabled: true, |
| 30 | maxAge: 60 * 5, // 5 minutes |
| 31 | }, |
| 32 | }, |
| 33 | trustedOrigins: [process.env.BETTER_AUTH_URL!], |
| 34 | }); |
| 35 | |
| 36 | export type Session = typeof auth.$Infer.Session; |