mirror of
https://gitlab.com/little-lines/backend.git
synced 2024-11-24 19:06:52 +00:00
config loginHandler
This commit is contained in:
parent
edc2231487
commit
1a7b7e4333
1 changed files with 21 additions and 17 deletions
|
@ -71,25 +71,29 @@ const updateUser = asyncHandler(async (req, res) => {
|
|||
|
||||
// Login user => api/users/login
|
||||
const loginUser = asyncHandler(async (req, res) => {
|
||||
const { email, password } = req.body;
|
||||
try {
|
||||
const { username, password } = req.body;
|
||||
|
||||
if(!email || !password) {
|
||||
return res.status(400).send('Please enter email & password');
|
||||
if(!username || !password) {
|
||||
return res.status(400).send('Please enter username & password');
|
||||
}
|
||||
|
||||
const users = await user.findOne({ username }).select('+password');
|
||||
|
||||
if(!users) {
|
||||
return res.status(400).send('Invalid username or Password');
|
||||
}
|
||||
|
||||
const isPasswordMatched = await users.comparePassword(password);
|
||||
|
||||
if(!isPasswordMatched) {
|
||||
return res.status(401).send('Invalid username or Password');
|
||||
}
|
||||
|
||||
sendToken(users, 200, res);
|
||||
} catch(err){
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
const users = await user.findOne({ email }).select('+password');
|
||||
|
||||
if(!users) {
|
||||
return res.status(400).send('Invalid Email or Password');
|
||||
}
|
||||
|
||||
const isPasswordMatched = await users.comparePassword(password);
|
||||
|
||||
if(!isPasswordMatched) {
|
||||
return res.status(401).send('Invalid Email or Password');
|
||||
}
|
||||
|
||||
sendToken(users, 200, res);
|
||||
});
|
||||
|
||||
// Logout user => api/users/logout
|
||||
|
|
Loading…
Reference in a new issue