From 356d470e16888c7e7a5ab033f9760c127bb65bc1 Mon Sep 17 00:00:00 2001 From: Mihai C <34626017+mihaic195@users.noreply.github.com> Date: Mon, 25 Oct 2021 12:29:54 +0300 Subject: [PATCH] fix: lowercase email on signup (#1039) --- pages/api/auth/signup.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pages/api/auth/signup.ts b/pages/api/auth/signup.ts index ebd464128b..b78fc1d28a 100644 --- a/pages/api/auth/signup.ts +++ b/pages/api/auth/signup.ts @@ -12,13 +12,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const data = req.body; const { email, password } = data; const username = slugify(data.username); + const userEmail = email.toLowerCase(); if (!username) { res.status(422).json({ message: "Invalid username" }); return; } - if (!email || !email.includes("@")) { + if (!userEmail || !userEmail.includes("@")) { res.status(422).json({ message: "Invalid email" }); return; } @@ -35,7 +36,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) username: username, }, { - email: email, + email: userEmail, }, ], }, @@ -43,7 +44,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) if (existingUser) { const message: string = - existingUser.email !== email ? "Username already taken" : "Email address is already registered"; + existingUser.email !== userEmail ? "Username already taken" : "Email address is already registered"; return res.status(409).json({ message }); } @@ -51,7 +52,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const hashedPassword = await hashPassword(password); await prisma.user.upsert({ - where: { email }, + where: { email: userEmail }, update: { username, password: hashedPassword, @@ -59,7 +60,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }, create: { username, - email, + email: userEmail, password: hashedPassword, }, });