From a745d8a60ad750a54b04010da38a8137ea045e4d Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Mon, 23 Jun 2025 04:32:14 -0400 Subject: [PATCH] fix: error in /auth/session (#21972) Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> --- packages/features/auth/lib/next-auth-options.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/features/auth/lib/next-auth-options.ts b/packages/features/auth/lib/next-auth-options.ts index 83fe86ba98..43de83ae20 100644 --- a/packages/features/auth/lib/next-auth-options.ts +++ b/packages/features/auth/lib/next-auth-options.ts @@ -438,7 +438,7 @@ export const getOptions = ({ encode: async ({ token, maxAge, secret }) => { log.debug("jwt:encode", safeStringify({ token, maxAge })); if (token?.sub && isNumber(token.sub)) { - const user = await prisma.user.findUnique({ + const user = await prisma.user.findFirst({ where: { id: Number(token.sub) }, select: { metadata: true }, }); @@ -489,7 +489,7 @@ export const getOptions = ({ } as JWT; } const autoMergeIdentities = async () => { - const existingUser = await prisma.user.findUnique({ + const existingUser = await prisma.user.findFirst({ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion where: { email: token.email! }, select: { @@ -855,7 +855,7 @@ export const getOptions = ({ // If the email address doesn't match, check if an account already exists // with the new email address. If it does, for now we return an error. If // not, update the email of their account and log them in. - const userWithNewEmail = await prisma.user.findUnique({ + const userWithNewEmail = await prisma.user.findFirst({ where: { email: user.email }, }); @@ -875,9 +875,12 @@ export const getOptions = ({ // a new account. If an account already exists with the incoming email // address return an error for now. - const existingUserWithEmail = await prisma.user.findUnique({ + const existingUserWithEmail = await prisma.user.findFirst({ where: { - email: user.email, + email: { + equals: user.email, + mode: "insensitive", + }, }, include: { password: true,