fix: lowercase email on signup (#1039)
parent
1043b31cc7
commit
356d470e16
|
@ -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,
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue