fix login

fix login by username to login by email
This commit is contained in:
NekoVari 2023-11-18 16:59:27 +07:00
parent 639b9fa718
commit e534935d80

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