mirror of
https://gitlab.com/little-lines/backend.git
synced 2024-11-24 11:06:50 +00:00
fix login
fix login by username to login by email
This commit is contained in:
parent
639b9fa718
commit
e534935d80
1 changed files with 6 additions and 6 deletions
|
@ -72,22 +72,22 @@ const updateUser = asyncHandler(async (req, res) => {
|
|||
// Login user => api/users/login
|
||||
const loginUser = asyncHandler(async (req, res) => {
|
||||
try {
|
||||
const { username, password } = req.body;
|
||||
const { email, password } = req.body;
|
||||
|
||||
if(!username || !password) {
|
||||
return res.status(400).send('Please enter username & password');
|
||||
if(!email || !password) {
|
||||
return res.status(400).send('Please enter email & password');
|
||||
}
|
||||
|
||||
const users = await user.findOne({ username }).select('+password');
|
||||
const users = await user.findOne({ email }).select('+password');
|
||||
|
||||
if(!users) {
|
||||
return res.status(400).send('Invalid username or Password');
|
||||
return res.status(400).send('Invalid Email');
|
||||
}
|
||||
|
||||
const isPasswordMatched = await users.comparePassword(password);
|
||||
|
||||
if(!isPasswordMatched) {
|
||||
return res.status(401).send('Invalid username or Password');
|
||||
return res.status(401).send('Invalid Password');
|
||||
}
|
||||
|
||||
sendToken(users, 200, res);
|
||||
|
|
Loading…
Reference in a new issue