I came to know the use of authenticate method in passport.js from the below link http://passportjs.org/guide/authenticate/
In my project I have the below code:
app.post('/login', function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
if (err) { console.log(err); return next(err) }
if (!user) {
return res.json(400, info);
}
req.logIn(user, function(err) {
if (err) { return next(err); }
return res.json(200, {user_id: user._id, url:"/user/home"});
});
})(req, res, next);
});
I have a call to the /login url in another file, like below
$http.post('/login', $scope.user).
success(function(data, status, headers, config) {
$window.location.href= data.url ? data.url : '/';
$scope.view.loading = false;
}).error(function(data, status, headers, config) {
console.log(data);
$scope.view.loading = false;
$scope.view.submitted = true;
$scope.view.serverError=data.message ? data.message : "Server Error!";
});
My doubt here is , how come the passport.authenticate is aware of the user credentials. While calling http.post, we are also sending $scope.user. But that is only 'data'. How come passport.authenticate is aware of the object 'user'?