server: ignore username case when signing up and in
This commit is contained in:
parent
cad10fb1fa
commit
61f7888f1b
1 changed files with 6 additions and 3 deletions
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue