6 node.js express passport-local meanjs passport.js
我已经下载了meanjs version@0.1.12.我已经使用了两个服务器用于前端我hvae使用angular with ionic它在localhost:3000中运行,对于后端我使用了meanjs.in that meanjs我创建了注册,登录和文章.当我使用meansjs作为后端和前端它工作正常.但是当我连接到另一台服务器(localhost:3000)注册并且签名工作正常但是当我创建文章时我得到401未经授权的那个请求的bcoz .isAuthenticated()函数.当我创建文章模块req.isAuthenticated()获取fail.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);
});
Run Code Online (Sandbox Code Playgroud)
路线:
app.route('/articles')
.get(users.requiresLogin,articles.list)
.post(users.requiresLogin,articles.create);
Run Code Online (Sandbox Code Playgroud)
登录检查
/**
* 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'
});
}
});
};
};
Run Code Online (Sandbox Code Playgroud)
我想我也有同样的问题。确保检查服务器端的策略文件夹。
roles: ['user'],
allows: [{
resources: '/articles',
permissions: ['get', 'post']
}, {
resources: '/articles/:articlesId',
permissions: ['get']
}, {
resources: '/articles',
permissions: ['post']
}]
Run Code Online (Sandbox Code Playgroud)
添加资源路径/articles和权限。
| 归档时间: |
|
| 查看次数: |
218 次 |
| 最近记录: |