Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions src/server/auth.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -78,25 +79,17 @@ const SplitProPrismaAdapter = (...args: Parameters<typeof PrismaAdapter>): 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<string, unknown>;
const knownAccountFields = new Set<string>(Object.values(Prisma.AccountScalarFieldEnum));

return originalLinkAccount(standardAccountData as AdapterAccount);
} else if (account.provider === 'gitlab') {
const { created_at: _createdAt, ...standardAccountData } = account as AdapterAccount &
Record<string, unknown>;
const sanitised = Object.fromEntries(
Object.entries(account as Record<string, unknown>).filter(([k]) =>
knownAccountFields.has(k),
),
) as AdapterAccount;

return originalLinkAccount(standardAccountData as AdapterAccount);
}

// Default: proceed directly
return originalLinkAccount(account);
return originalLinkAccount(sanitised);
},
} as Adapter;
};
Expand Down
Loading