I'm making an API. When I send correct data for login, I get JSON but when I send incorrect data, I get this [object object] message, why?
When the correct information is provided.
Here is my code.
router.route('/login').post(function (req, res, next) {
console.log('i should be here when path match to login', req.body);
UserModel.findOne({
username: req.body.username,
})
.exec(function (err, user) {
if (err) {
return next(err);
}
if (user) {
var passwordMatch = passwordHash.verify(req.body.password, user.password);
if (passwordMatch) {
var token = generateToken(user);
res.status(200).json({
user: user,
token: token
});
} else {
next({
message: "password didnot match",
status: 400
})
}
} else {
next({
message: 'Invalid Username',
status: 400
})
}
});
});