When using the waterline ORM, if I want to consume the bluebird promise api thats shipped by default how to I pass the processing back to the controller.
Below is the code :
module.exports = {
//Authenticate
auth: function (req, res) {
user = req.allParams();
//Authenticate
User.authenticate(user, function (response) {
console.log(response);
if (response == true) {
res.send('Authenticated');
} else {
res.send('Failed');
}
});
}
};
module.exports = {
// Attributes
// Authenticate a user
authenticate: function (req, cb) {
User.findOne({
username: req.username
})
.then(function (user) {
var bcrypt = require('bcrypt');
// check for the password
bcrypt.compare(req.password, user.password, function (err, res) {
console.log(res);
if (res == true) {
cb(true);
} else {
cb(false);
}
});
})
.catch(function (e) {
console.log(e);
});
}
};
I am simply trying to implement a authentication function. The business logic is straight forward. What I am confused of is how the request flow is handed back to the controller since. The promise doesn't respond if I try to return a response, but doing a cb(value) works.