From e78fb22451834fc5acae9013ce62fa802ebade61 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Wed, 3 May 2023 18:40:28 +0530 Subject: [PATCH] [URGENT] Hotfix: re-adds the password and username set check in signup (#8638) * Check for existing password and username to ensure it isn't an invite * added check with verified to allow SAML linking * wrong verified check lol * updated comment * unintended --- apps/web/pages/api/auth/signup.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/web/pages/api/auth/signup.ts b/apps/web/pages/api/auth/signup.ts index 921cc17a52..b06f39af8c 100644 --- a/apps/web/pages/api/auth/signup.ts +++ b/apps/web/pages/api/auth/signup.ts @@ -36,14 +36,25 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) return; } - // There is actually an existingUser if username matches - // OR if email matches and both username and password are set + // There is an existingUser if the username matches + // OR if the email matches AND either the email is verified + // or both username and password are set const existingUser = await prisma.user.findFirst({ where: { OR: [ { username }, { - AND: [{ email: userEmail }], + AND: [ + { email: userEmail }, + { + OR: [ + { emailVerified: { not: null } }, + { + AND: [{ password: { not: null } }, { username: { not: null } }], + }, + ], + }, + ], }, ], },