我已经下载了meanjs[电子邮件受保护] /cdn-cgi/l/email-protection我使用了两台服务器作为前端,我使用了 Angular 和 ionic,它在 localhost:3000 中运行,对于后端,我使用了meanjs。在meanjs中,我创建了注册、登录和文章。当我使用meanjs作为后端时,前端工作正常。但是当我连接到另一台服务器(localhost:3000)时,注册和登录工作正常,但是当我创建文章时,我收到该 req.isAuthenticated() 函数的 401 未经授权的 bcoz。当我创建文章时模块 req.isAuthenticated() 获取 failed.req.isAuthenticated() 我不知道我应该为这个函数传递什么我已经包含了我的代码任何人都可以帮助我
现在我正在传递这样的数据
$http.post('http://192.168.1.14:3000/articles', credentials).success(function(response,data,errorResponse) {
// If successful we assign the response to the global user model
//$scope.authentication.user =response;
console.log(response);
console.log(data);
// And redirect to the index page
$location.path('/tab/account');
}, function(response,data,errorResponse) {
$scope.error = errorResponse.data.message;
console.log($scope.error);
console.log(data);
});
routes:
app.route('/articles')
.get(users.requiresLogin,articles.list)
.post(users.requiresLogin,articles.create);
登录检查
/**
* Require login routing middleware
*/
exports.requiresLogin = function(req, res, next) {
//console.log(req.isAuthenticated());
console.log(req);
if (!req.isAuthenticated()) {
return res.status(401).send({
message: 'User is not logged in'
});
}
next();
};
/**
* User authorizations routing middleware
*/
exports.hasAuthorization = function(roles) {
var _this = this;
console.log('sss');
return function(req, res, next) {
_this.requiresLogin(req, res, function() {
if (_.intersection(req.user.roles, roles).length) {
return next();
} else {
return res.status(403).send({
message: 'User is not authorized'
});
}
});
};
};