// auth.ts
import 'server-only';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { db } from '@/db';
import { captcha, twoFactor } from 'better-auth/plugins';
import { nextCookies } from 'better-auth/next-js';
import { betterAuth } from 'better-auth';
import { config } from 'dotenv';
import { schema } from '@/db/schema';
config({ path: '.env' });
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: 'pg',
usePlural: true,
camelCase: false,
schema,
}),
emailAndPassword: {
enabled: true,
disableSignUp: true,
},
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60, // in seconds
},
expiresIn: 604800, // 7 days
storeSessionInDatabase: true,
},
rateLimit: {
storage: 'database',
},
appName: 'GN Inventory',
user: {
additionalFields: {
role: {
type: 'string',
required: true,
defaultValue: 'viewer',
input: false,
},
},
},
plugins: [
twoFactor(),
nextCookies(),
captcha({
provider: 'hcaptcha',
siteKey: 'secret',
secretKey: process.env.HCAPTCHA_SECRET!,
}),
],
advanced: {
cookiePrefix: 'gn-inventory',
},
});
// auth.ts
import 'server-only';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { db } from '@/db';
import { captcha, twoFactor } from 'better-auth/plugins';
import { nextCookies } from 'better-auth/next-js';
import { betterAuth } from 'better-auth';
import { config } from 'dotenv';
import { schema } from '@/db/schema';
config({ path: '.env' });
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: 'pg',
usePlural: true,
camelCase: false,
schema,
}),
emailAndPassword: {
enabled: true,
disableSignUp: true,
},
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60, // in seconds
},
expiresIn: 604800, // 7 days
storeSessionInDatabase: true,
},
rateLimit: {
storage: 'database',
},
appName: 'GN Inventory',
user: {
additionalFields: {
role: {
type: 'string',
required: true,
defaultValue: 'viewer',
input: false,
},
},
},
plugins: [
twoFactor(),
nextCookies(),
captcha({
provider: 'hcaptcha',
siteKey: 'secret',
secretKey: process.env.HCAPTCHA_SECRET!,
}),
],
advanced: {
cookiePrefix: 'gn-inventory',
},
});