One way to get started is to create a service in Angular that uses $ http to reach your endpoint in Express. $ http returns a promise with success and error methods that you can use to change state. If you are building a single page application (SPA), this is probably all you need to know. For instance:
UserService.$inject = ['$http', '$state'];
function UserService($http, $state) {
this.loginUser = function (user) {
$http.post("/api/login", user)
.success(function (data, status) {
console.log('Successful login.');
console.log('data = ' + data);
console.log('status = ' + status);
$state.go('welcome');
})
.error(function (data) {
console.log('Error: ' + data);
$state.go('somewhereelse');
});
};
$state.go - UI Router, .
Express Passport . :
app.post('/api/login', function(req, res, next) {
passport.authenticate('local-login', function(err, user, info) {
if (err) {
return next(err);
}
if (user === false) {
res.status(401).send(info.message);
} else {
res.status(200).send(info.message);
}
})(req, res, next);
});
Passport , . , 200 Angular, .success. 401 Unauthorized .error.