之前我遇到过这个问题,我知道它可能是由多个res.json引起的,但在这种情况下我想知道为什么它有错误
router.post('/', function(req, res) {
var data = {
username: req.body.username,
password: req.body.password
};
Owner.getUser(data,function(err,response){
if(err)
throw err
if(response){
console.log(response.password);
var createHash = function(password){
return bCrypt.hashSync(password, bCrypt.genSaltSync(10), null);
};
Owner.comparePassword(response.password, createHash(data.password) , function(err, result){
if(result === true){
res.json({msg: 1});
}else{
res.json({msg: 'Error, Incorrect password!'});
}
});
}else{
res.json({msg: 'No such account exists! '});
}
});
有什么想法吗?