added betterauth
This commit is contained in:
36
src/lib/server/auth.ts
Normal file
36
src/lib/server/auth.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { genericOAuth } from "better-auth/plugins";
|
||||
import {
|
||||
BETTER_AUTH_SECRET,
|
||||
BETTER_AUTH_URL,
|
||||
OIDC_CLIENT_ID,
|
||||
OIDC_CLIENT_SECRET,
|
||||
OIDC_ISSUER_DISCOVERY_URL
|
||||
} from '$app/env/private';
|
||||
import { betterAuth } from "better-auth";
|
||||
import { prismaAdapter } from "better-auth/adapters/prisma";
|
||||
import { db } from "./db";
|
||||
import { sveltekitCookies } from "better-auth/svelte-kit";
|
||||
import { getRequestEvent } from "$app/server";
|
||||
|
||||
const oidc = OIDC_ISSUER_DISCOVERY_URL && OIDC_CLIENT_ID && OIDC_CLIENT_SECRET
|
||||
? [
|
||||
genericOAuth({
|
||||
config: [
|
||||
{
|
||||
providerId: 'oidc',
|
||||
clientId: OIDC_CLIENT_ID,
|
||||
clientSecret: OIDC_CLIENT_SECRET,
|
||||
discoveryUrl: OIDC_ISSUER_DISCOVERY_URL,
|
||||
scopes: ['openid', 'profile', 'email'],
|
||||
}
|
||||
]
|
||||
})
|
||||
] : [];
|
||||
|
||||
export const auth = betterAuth({
|
||||
secret: BETTER_AUTH_SECRET,
|
||||
baseURL: BETTER_AUTH_URL,
|
||||
database: prismaAdapter(db, { provider: 'postgresql' }),
|
||||
emailAndPassword: { enabled: true },
|
||||
plugins: [...oidc, sveltekitCookies(getRequestEvent)],
|
||||
});
|
||||
@@ -1,13 +1,13 @@
|
||||
|
||||
import { PrismaClient } from '#lib/generated/prisma/client.ts';
|
||||
import { dev } from '$app/env';
|
||||
import { DATABASE_URL } from '$app/env/private';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { env } from 'process';
|
||||
|
||||
const globalForDb = globalThis as unknown as { db?: PrismaClient };
|
||||
|
||||
function createClient() {
|
||||
const adapter = new PrismaPg({ connectionString: env.DATABASE_URL });
|
||||
const adapter = new PrismaPg({ connectionString: DATABASE_URL });
|
||||
return new PrismaClient({ adapter });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user