Files
taskarr-mgr/src/lib/server/auth.ts
Milas Holsting 921560d14d
All checks were successful
Build and Push Container Image / build-and-push (push) Successful in 5m6s
fix
2026-05-26 18:04:15 +02:00

40 lines
1.2 KiB
TypeScript

import { betterAuth } from 'better-auth/minimal';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { sveltekitCookies } from 'better-auth/svelte-kit';
import { env } from '$env/dynamic/private';
import { getRequestEvent } from '$app/server';
import { db } from '$lib/server/db';
function createAuth() {
const origin = env.ORIGIN;
if (!origin) throw new Error('ORIGIN is not set');
const secret = env.BETTER_AUTH_SECRET;
if (!secret) throw new Error('BETTER_AUTH_SECRET is not set');
const clientId = env.GITHUB_CLIENT_ID;
if (!clientId) throw new Error('GITHUB_CLIENT_ID is not set');
const clientSecret = env.GITHUB_CLIENT_SECRET;
if (!clientSecret) throw new Error('GITHUB_CLIENT_SECRET is not set');
return betterAuth({
baseURL: origin,
secret,
database: drizzleAdapter(db, { provider: 'pg' }),
emailAndPassword: { enabled: true },
socialProviders: {
github: { clientId, clientSecret }
},
plugins: [
sveltekitCookies(getRequestEvent)
]
});
}
let _auth: ReturnType<typeof betterAuth>;
export const auth = new Proxy({} as ReturnType<typeof betterAuth>, {
get(target, prop) {
if (!_auth) _auth = createAuth();
return Reflect.get(_auth, prop, target);
}
});