auth & sidebar

This commit is contained in:
Face 2025-05-22 13:17:11 +03:00
parent 8086aa8f38
commit af078e7ba2
74 changed files with 3262 additions and 133 deletions

56
website/src/lib/auth.ts Normal file
View file

@ -0,0 +1,56 @@
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { apiKey } from "better-auth/plugins";
import { env } from '$env/dynamic/private';
import { db } from "./server/db";
import { eq } from "drizzle-orm";
if (!env.GOOGLE_CLIENT_ID) throw new Error('GOOGLE_CLIENT_ID is not set');
if (!env.GOOGLE_CLIENT_SECRET) throw new Error('GOOGLE_CLIENT_SECRET is not set');
export const auth = betterAuth({
baseURL: env.PUBLIC_BETTER_AUTH_URL,
secret: env.PRIVATE_BETTER_AUTH_SECRET,
appName: "Rugplay",
database: drizzleAdapter(db, {
provider: "pg",
}),
socialProviders: {
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
}
},
session: {
cookieCache: {
enabled: true,
maxAge: 60 * 5, // 5 minutes
}
},
user: {
additionalFields: {
isAdmin: {
type: "boolean",
required: true,
defaultValue: false,
input: false
},
isBanned: {
type: "boolean",
required: true,
defaultValue: false,
input: false
},
banReason: {
type: "string",
required: false,
defaultValue: null,
input: false
}
},
deleteUser: { enabled: true }
},
});