4bba529ba8
Support TOTP 2fa, allow for changing password, add session management and account removal.
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { drizzleAdapter } from "@better-auth/drizzle-adapter/relations-v2";
|
|
import { db } from "../server/lib/db";
|
|
import { betterAuth } from 'better-auth/minimal';
|
|
import { twoFactor } from 'better-auth/plugins/two-factor';
|
|
import * as schema from '../drizzle/schema';
|
|
|
|
export const auth = betterAuth({
|
|
database: drizzleAdapter(db, {
|
|
provider: "pg",
|
|
schema,
|
|
usePlural: true,
|
|
}),
|
|
|
|
session: {
|
|
expiresIn: 60 * 60 * 24 * 30, // 1 month
|
|
updateAge: 60 * 60 * 24 * 1, // 1 day
|
|
cookieCache: {
|
|
enabled: true,
|
|
maxAge: 5 * 60,
|
|
},
|
|
},
|
|
|
|
baseURL: process.env.NUXT_PUBLIC_URL ?? 'http://localhost:3000',
|
|
trustedOrigins: [process.env.NUXT_PUBLIC_URL ?? 'http://localhost:3000'],
|
|
|
|
plugins: [
|
|
twoFactor({
|
|
issuer: 'Veridian',
|
|
}),
|
|
],
|
|
|
|
emailAndPassword: {
|
|
// if DISABLE_LOCAL_AUTH is set to "1" or "true" then local auth is disabled
|
|
enabled: process.env.DISABLE_LOCAL_AUTH?.toLowerCase() !== 'true' && process.env.DISABLE_LOCAL_AUTH !== '1',
|
|
disableSignUp: process.env.DISABLE_SIGNUP?.toLowerCase() === 'true' || process.env.DISABLE_SIGNUP === '1',
|
|
},
|
|
});
|