INVALID_OAUTH_CONFIGURATION in Sveltekit

Hello, I have this configuration

import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { genericOAuth } from 'better-auth/plugins/generic-oauth';
import { env } from '$env/dynamic/private';
import * as schema from '$lib/database/schema';
import { db } from './database';

export const auth = betterAuth({
    database: drizzleAdapter(db, { provider: 'pg', schema }),
    plugins: [
        genericOAuth({
            config: [
                {
                    providerId: 'keycloak',
                    clientId: env.KEYCLOAK_CLIENT_ID!,
                    clientSecret: env.KEYCLOAK_CLIENT_SECRET!,
                    discoveryUrl: env.KEYCLOAK_DISCOVERY_URL,
                    scopes: ['openid', 'profile', 'email']
                }
            ]
        })
    ]
});

Everything works fine in development (pnpm dev) but when i try the built app (pnpm build && pnpm preview), i get the error:
{code: "INVALID_OAUTH_CONFIGURATION", message: "Invalid OAuth configuration"}


I have the BETTER_AUTH_URL environment variable set properly!

Anyone ever faced something like this? this is really weird.
Thanks in advance
Was this page helpful?