This commit is contained in:
p11037 2023-11-18 23:59:57 +07:00
commit 0feed90cfc

View file

@ -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);