#37 As an existing user, so that I know I might have mis-typed my login details, I want an error message to be displayed when I'm unable to login. #219
Will use username acquired from login form to search db for matching user,
if username isn't found an error message is returned "Invalid Username or Password".
If username does match, password hash is compared with the users password on the db using bcrypt.
If the password's don't match the error message above is returned.
Will require JWTwebtoken package and bcrypt.
where: {
username: username
}
});
if (!foundUser) {
return res.status(401).json({ error: 'Invalid username or password.' });
}
const passwordsMatch = await bcrypt.compare(password, foundUser.password);
if (!passwordsMatch) {
return res.status(401).json({ error: 'Invalid username or password.' });
}```
Backend:
Will use username acquired from login form to search db for matching user, if username isn't found an error message is returned "Invalid Username or Password". If username does match, password hash is compared with the users password on the db using bcrypt. If the password's don't match the error message above is returned.
Will require JWTwebtoken package and bcrypt.