From 61f7888f1b603691a256a97b4a397d715361a875 Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Wed, 9 Mar 2022 16:22:52 -0800 Subject: [PATCH] server: ignore username case when signing up and in --- server/src/routes/users.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/src/routes/users.ts b/server/src/routes/users.ts index 8bf410f1..969b1996 100644 --- a/server/src/routes/users.ts +++ b/server/src/routes/users.ts @@ -54,14 +54,16 @@ users.post('/signup', async (req, res, next) => { throw new Error("Please provide a username and password") } - const existingUser = await User.findOne({ where: { username: req.body.username } }) + const username = req.body.username.toLowerCase(); + + const existingUser = await User.findOne({ where: { username: username } }) if (existingUser) { throw new Error("Username already exists") } const salt = await genSalt(10) const user = { - username: req.body.username as string, + username: username as string, password: await hash(req.body.password, salt) } @@ -81,7 +83,8 @@ users.post('/login', async (req, res, next) => { throw new Error("Missing username or password") } - const user = await User.findOne({ where: { username: req.body.username } }); + const username = req.body.username.toLowerCase(); + const user = await User.findOne({ where: { username: username } }); if (!user) { throw new Error("User does not exist"); }