mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-29 18:26:34 +02:00
🔨 Patch OAuth providers returning unexpected fields (#972)
This commit is contained in:
parent
48421616ea
commit
5898755bbd
2 changed files with 39 additions and 2 deletions
|
@ -1,4 +1,3 @@
|
||||||
import { PrismaAdapter } from "@auth/prisma-adapter";
|
|
||||||
import { RegistrationTokenPayload } from "@rallly/backend";
|
import { RegistrationTokenPayload } from "@rallly/backend";
|
||||||
import { decryptToken } from "@rallly/backend/session";
|
import { decryptToken } from "@rallly/backend/session";
|
||||||
import { generateOtp, randomid } from "@rallly/backend/utils/nanoid";
|
import { generateOtp, randomid } from "@rallly/backend/utils/nanoid";
|
||||||
|
@ -19,6 +18,7 @@ import EmailProvider from "next-auth/providers/email";
|
||||||
import { Provider } from "next-auth/providers/index";
|
import { Provider } from "next-auth/providers/index";
|
||||||
|
|
||||||
import { absoluteUrl } from "@/utils/absolute-url";
|
import { absoluteUrl } from "@/utils/absolute-url";
|
||||||
|
import { CustomPrismaAdapter } from "@/utils/auth/custom-prisma-adapter";
|
||||||
import { mergeGuestsIntoUser } from "@/utils/auth/merge-user";
|
import { mergeGuestsIntoUser } from "@/utils/auth/merge-user";
|
||||||
import { isOIDCEnabled, oidcName } from "@/utils/constants";
|
import { isOIDCEnabled, oidcName } from "@/utils/constants";
|
||||||
import { emailClient } from "@/utils/emails";
|
import { emailClient } from "@/utils/emails";
|
||||||
|
@ -133,7 +133,7 @@ if (isOIDCEnabled) {
|
||||||
|
|
||||||
const getAuthOptions = (...args: GetServerSessionParams) =>
|
const getAuthOptions = (...args: GetServerSessionParams) =>
|
||||||
({
|
({
|
||||||
adapter: PrismaAdapter(prisma),
|
adapter: CustomPrismaAdapter(prisma),
|
||||||
secret: process.env.SECRET_PASSWORD,
|
secret: process.env.SECRET_PASSWORD,
|
||||||
session: {
|
session: {
|
||||||
strategy: "jwt",
|
strategy: "jwt",
|
||||||
|
|
37
apps/web/src/utils/auth/custom-prisma-adapter.ts
Normal file
37
apps/web/src/utils/auth/custom-prisma-adapter.ts
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/**
|
||||||
|
* This is a modified version of the default Prisma adapter that
|
||||||
|
* ignores fields returned by the OAuth provider that are not
|
||||||
|
* defined in the database schema when creating an account.
|
||||||
|
*
|
||||||
|
* This resolves issues where some OAuth providers return unexpected
|
||||||
|
* fields in their response which cause the Prisma adapter to throw
|
||||||
|
* an error.
|
||||||
|
*
|
||||||
|
* See: https://github.com/lukevella/rallly/issues/949
|
||||||
|
*/
|
||||||
|
import { PrismaAdapter } from "@auth/prisma-adapter";
|
||||||
|
import { PrismaClient } from "@rallly/database";
|
||||||
|
import { Adapter, AdapterAccount } from "next-auth/adapters";
|
||||||
|
|
||||||
|
export function CustomPrismaAdapter(client: PrismaClient): Adapter {
|
||||||
|
return {
|
||||||
|
...PrismaAdapter(client),
|
||||||
|
linkAccount: (data) => {
|
||||||
|
return client.account.create({
|
||||||
|
data: {
|
||||||
|
userId: data.userId,
|
||||||
|
type: data.type,
|
||||||
|
provider: data.provider,
|
||||||
|
providerAccountId: data.providerAccountId,
|
||||||
|
access_token: data.access_token as string,
|
||||||
|
expires_at: data.expires_at as number,
|
||||||
|
id_token: data.id_token as string,
|
||||||
|
token_type: data.token_type as string,
|
||||||
|
refresh_token: data.refresh_token as string,
|
||||||
|
scope: data.scope as string,
|
||||||
|
session_state: data.session_state as string,
|
||||||
|
},
|
||||||
|
}) as unknown as AdapterAccount;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue