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 data = req.body;
|
||||||
const { email, password } = data;
|
const { email, password } = data;
|
||||||
const username = slugify(data.username);
|
const username = slugify(data.username);
|
||||||
|
const userEmail = email.toLowerCase();
|
||||||
|
|
||||||
if (!username) {
|
if (!username) {
|
||||||
res.status(422).json({ message: "Invalid username" });
|
res.status(422).json({ message: "Invalid username" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!email || !email.includes("@")) {
|
if (!userEmail || !userEmail.includes("@")) {
|
||||||
res.status(422).json({ message: "Invalid email" });
|
res.status(422).json({ message: "Invalid email" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +36,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
username: username,
|
username: username,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: email,
|
email: userEmail,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -43,7 +44,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
|
|
||||||
if (existingUser) {
|
if (existingUser) {
|
||||||
const message: string =
|
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 });
|
return res.status(409).json({ message });
|
||||||
}
|
}
|
||||||
|
@ -51,7 +52,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
const hashedPassword = await hashPassword(password);
|
const hashedPassword = await hashPassword(password);
|
||||||
|
|
||||||
await prisma.user.upsert({
|
await prisma.user.upsert({
|
||||||
where: { email },
|
where: { email: userEmail },
|
||||||
update: {
|
update: {
|
||||||
username,
|
username,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
|
@ -59,7 +60,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
username,
|
username,
|
||||||
email,
|
email: userEmail,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue