chess-monolith / src /lib /auth.ts
mighttguy's picture
Move all files to repository root for Hugging Face
c30da20
Raw History Blame Contribute Delete
1.24 kB
import "dotenv/config";
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "../infrastructure/db/db";
import { v7 as uuidv7 } from "uuid";
import { authHooks } from "./utils/auth-hooks";
import { env } from "../config/env";
export const auth = betterAuth({
secret: env.BETTER_AUTH_SECRET,
baseURL: env.BETTER_AUTH_URL,
database: drizzleAdapter(db, {
provider: "pg",
}),
emailAndPassword: {
enabled: true,
},
trustedOrigins: [process.env.CLIENT_URL || "http://localhost:3000"],
session: {
expiresIn: 60 * 60 * 24 * 7,
updateAge: 60 * 60 * 24 * 7,
cookieCache: {
enabled: true,
maxAge: 1,
},
},
user: {
additionalFields: {
username: {
type: "string",
required: true,
},
wins: {
type: "number",
defaultValue: 0,
},
losses: {
type: "number",
defaultValue: 0,
},
draws: {
type: "number",
defaultValue: 0,
},
rating: {
type: "number",
defaultValue: 1000,
},
},
},
hooks: authHooks,
advanced: {
database: {
generateId: () => uuidv7(),
},
},
});