All checks were successful
Build and Push Container Image / build-and-push (push) Successful in 5m6s
40 lines
1.2 KiB
TypeScript
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);
|
|
}
|
|
});
|