From 58f4224c6694d88bd6259ad79ebb8911c1d9e0a4 Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Fri, 25 Aug 2023 10:19:03 +0100 Subject: [PATCH] Fix invite flow (#10951) --- apps/web/pages/api/auth/signup.ts | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/apps/web/pages/api/auth/signup.ts b/apps/web/pages/api/auth/signup.ts index 150d027921..f53421fb9c 100644 --- a/apps/web/pages/api/auth/signup.ts +++ b/apps/web/pages/api/auth/signup.ts @@ -39,19 +39,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const username = slugify(data.username); const userEmail = email.toLowerCase(); - const validationResponse = ( - incomingEmail: string, - validation: { isValid: boolean; email: string | undefined } - ) => { - const { isValid, email } = validation; - if (!isValid) { - const message: string = - email !== incomingEmail ? "Username already taken" : "Email address is already registered"; - - return res.status(409).json({ message }); - } - }; - if (!username) { res.status(422).json({ message: "Invalid username" }); return; @@ -79,11 +66,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } if (foundToken?.teamId) { const teamUserValidation = await validateUsernameInTeam(username, userEmail, foundToken?.teamId); - return validationResponse(userEmail, teamUserValidation); + if (!teamUserValidation.isValid) { + return res.status(409).json({ message: "Username or email is already taken" }); + } } } else { const userValidation = await validateUsername(username, userEmail); - return validationResponse(userEmail, userValidation); + if (!userValidation.isValid) { + return res.status(409).json({ message: "Username or email is already taken" }); + } } const hashedPassword = await hashPassword(password); @@ -94,7 +85,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) id: foundToken.teamId, }, }); - if (team) { const teamMetadata = teamMetadataSchema.parse(team?.metadata);