50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { betterAuth } from 'better-auth';
|
|
import { bearer } from 'better-auth/plugins';
|
|
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
|
|
import { db } from '../db';
|
|
import * as schema from '../db/schema';
|
|
|
|
export const auth = betterAuth({
|
|
database: drizzleAdapter(db, {
|
|
provider: 'pg',
|
|
schema: {
|
|
user: schema.users,
|
|
session: schema.sessions,
|
|
account: schema.accounts,
|
|
verification: schema.verifications,
|
|
},
|
|
}),
|
|
plugins: [
|
|
bearer(), // Enable bearer token auth for mobile apps
|
|
],
|
|
emailAndPassword: {
|
|
enabled: true,
|
|
requireEmailVerification: false, // Enable later for production
|
|
},
|
|
session: {
|
|
expiresIn: 60 * 60 * 24 * 7, // 7 days
|
|
updateAge: 60 * 60 * 24, // Update session every day
|
|
cookieCache: {
|
|
enabled: true,
|
|
maxAge: 60 * 5, // 5 minutes
|
|
},
|
|
},
|
|
advanced: {
|
|
crossSubDomainCookies: {
|
|
enabled: true,
|
|
domain: process.env.COOKIE_DOMAIN || '.thenetwork.donovankelly.xyz',
|
|
},
|
|
defaultCookieAttributes: {
|
|
secure: true,
|
|
sameSite: 'none',
|
|
},
|
|
},
|
|
trustedOrigins: [
|
|
process.env.APP_URL || 'http://localhost:3000',
|
|
...(process.env.ALLOWED_ORIGINS?.split(',') || []),
|
|
],
|
|
});
|
|
|
|
export type Session = typeof auth.$Infer.Session;
|
|
export type User = typeof auth.$Infer.Session.user;
|