From bb2754daacdc2849eb77b6e0f3f8fe486456f26d Mon Sep 17 00:00:00 2001 From: Miklos Mandoki Date: Mon, 20 Jul 2026 20:26:54 +1000 Subject: [PATCH] fix: prevent prisma crash on OIDC accounts with non-standard fields --- src/server/auth.ts | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/server/auth.ts b/src/server/auth.ts index dff93589..bbc73e30 100644 --- a/src/server/auth.ts +++ b/src/server/auth.ts @@ -1,4 +1,5 @@ import { PrismaAdapter } from '@next-auth/prisma-adapter'; +import { Prisma } from '@prisma/client'; import { type GetServerSidePropsContext } from 'next'; import { type DefaultSession, type NextAuthOptions, type User, getServerSession } from 'next-auth'; import { type Adapter, type AdapterAccount, type AdapterUser } from 'next-auth/adapters'; @@ -78,25 +79,17 @@ const SplitProPrismaAdapter = (...args: Parameters): Adapt throw new Error('Adapter is missing the linkAccount method.'); } - // Keycloak and Gitlab provide some non-standard fields that do not exist in the prisma schema. + // OIDC providers can provide non-standard fields that do not exist in the prisma schema. // We strip them out before passing them on to the original adapter. - if (account.provider === 'keycloak') { - const { - 'not-before-policy': _notBeforePolicy, - refresh_expires_in: _refresh_expires_in, - ...standardAccountData - } = account as AdapterAccount & Record; + const knownAccountFields = new Set(Object.values(Prisma.AccountScalarFieldEnum)); - return originalLinkAccount(standardAccountData as AdapterAccount); - } else if (account.provider === 'gitlab') { - const { created_at: _createdAt, ...standardAccountData } = account as AdapterAccount & - Record; + const sanitised = Object.fromEntries( + Object.entries(account as Record).filter(([k]) => + knownAccountFields.has(k), + ), + ) as AdapterAccount; - return originalLinkAccount(standardAccountData as AdapterAccount); - } - - // Default: proceed directly - return originalLinkAccount(account); + return originalLinkAccount(sanitised); }, } as Adapter; };