Mean.js req.isAuthenticated显示失败? [英] Mean.js req.isAuthenticated is showing fail?
问题描述
我下载了meanjs version@0.1.12.在这里我使用了两台服务器作为前端,我在localhost:3000中使用了angular与ionic,对于后端,我使用了meanjs.in,我创建了signup,当我将Meansjs用作后端和前端时,它工作正常.但是当我连接到另一台服务器(localhost:3000)时,注册和登录工作正常,但是当我创建文章时,我会得到401未经授权的Bcoz req.isAuthenticated()函数的功能.每当我创建商品模块req.isAuthenticated()时都失败了.req.isAuthenticated()我不知道该函数应该传递什么,我已经包含了我的代码有人可以帮助我
i have downloaded meanjs version@0.1.12.here i have used two servers for front end i hvae used angular with ionic its running in localhost:3000,for backend i have used meanjs.in that meanjs i have created signup,signin and articles.when ever i am using meansjs as a backend and front end it's working fine .but when i connect to another server(localhost:3000) signup and signin working fine but when ever i am creating articles i am getting 401 unauthorized bcoz of that req.isAuthenticated() function.when ever i create article module req.isAuthenticated() getting fail.req.isAuthenticated() i dono what should i pass for this function i have included my code anyone help me out
现在我正在传递这样的数据
now i am passing data like this
$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);
});
路线:
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'
});
}
});
};
};
推荐答案
我认为我遇到了同样的问题.确保检查服务器端的策略文件夹.
I think I had the same problem. Make sure to check your policies folder on the server side.
roles: ['user'],
allows: [{
resources: '/articles',
permissions: ['get', 'post']
}, {
resources: '/articles/:articlesId',
permissions: ['get']
}, {
resources: '/articles',
permissions: ['post']
}]
添加资源路径/articles
和权限.
这篇关于Mean.js req.isAuthenticated显示失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!