0
我試圖實現一個簡單的登錄,但有一個小問題。 bcrypt
返回response
,所以當我嘗試res.send("stuff")
時,它會返回一個錯誤,因爲它認爲我試圖訪問res對象的屬性而不是express.js的響應功能。 (如我錯了請糾正我)。Express.js響應未定義錯誤
ReferenceError: response is not defined at authController.js:79:21
exports.loginModalPost = function (req, res) {
// post
var email = req.body.email;
var password = req.body.password;
// email & password validation.
user.where('email', email).fetch().then(function (data) {
if (data) {
data = data.toJSON();
bcrypt.compare(password, data.password_hash, function (err, res) {
if(res === true) {
res.send("login is valid");
} else {
// return err, but don't say that password is wrong to the end user.
res.send("password is wrong");
}
});
} else {
// email is wrong, no need to check password.
// return err, but don't say that email is wrong.
res.send("email is wrong");
}
});
};