Skip to content

Scheduling infrastructure for absolutely everyone.

fix: lowercase email on signup (#1039)

Mihai C356d470e1688
diff --git a/pages/api/auth/signup.ts b/pages/api/auth/signup.ts
index ebd464128bd..b78fc1d28af 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,
},
});