首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Meanjs禁忌误差

Meanjs禁忌误差
EN

Stack Overflow用户
提问于 2018-02-20 16:19:13
回答 1查看 81关注 0票数 1

我是AngularJs中的一只新蜜蜂,下面是Meanjs生成器创建的策略代码,为了学习目的,我创建了一个库管理系统,我面临的问题是当我测试我的服务器代码时,即通过浏览器URL测试API .我得到了http://localhost:3000/api/searchbooks/bookname/davincicode作为JSON对象的结果

但是在url下面,它给了我{message: 'User is not authorized'}

http://localhost:3000/api/searchbooks/bookname/davincicode/bookName

代码语言:javascript
复制
exports.invokeRolesPolicies = function () {
  acl.allow([  
{
    roles: ['user'],
    allows: [{
      resources: '/api/searchbooks',
      permissions: ['get']
    }, {
      resources: '/api/searchbooks/bookname/:searchbookName',
      permissions: ['get']
    }]
},
{
   roles: ['user'],
   allows: [{
     resources: '/api/searchbooks/bookname',
     permissions: ['get']
   }, {
     resources: '/api/searchbooks/bookname/:searchbookName/:action',
     permissions: ['get']
   }]
}

])};

exports.isAllowed = function (req, res, next) {
  var roles = (req.user) ? req.user.roles : ['guest'];

  // If an Searchbook is being processed and the current user created it then allow any manipulation
  if (req.searchbook && req.user && req.searchbook.user && req.searchbook.user.id === req.user.id) {
    return next();
  }
  // Check for user roles
  acl.areAnyRolesAllowed(roles, req.route.path, req.method.toLowerCase(), function (err, isAllowed) {
    if (err) {
      // An authorization error occurred
      return res.status(500).send('Unexpected authorization error');
    } else {
      if (isAllowed) {
        // Access granted! Invoke next middleware
        return next();
      } else {
        return res.status(403).json({
          message: 'User is not authorized'
        });
      }
    }
  });
};

我检查了我的角色,它只是作为user,无法在其他地方找到如此具体的问题,请帮助或提供一些指点。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-21 05:08:35

我在路由部分( app.route('/api/searchbooks/bookname/:searchbookName/:actionValue').all(searchbooksPolicy.isAllowed) .get(searchbooks.read) )出现了错误

在策略url中,它的action和我必须将actionValue作为参数名。

so passing incorrect parameter name was an issue..

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48889676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档