Group/rule-based authorization approach in node.js and express.js

后端 未结 6 1480
鱼传尺愫
鱼传尺愫 2021-01-30 00:31

What are good strategies for role-based authorization in express.js? Especially with express-resource?

With Express-resource there are no handlers, so I think there are

6条回答
  •  有刺的猬
    2021-01-30 00:56

    Connect-roles is quite good, simple and the documentation is also very clear.

    var user = roles;
    
    app.get('/profile/:id', user.can('edit profile'), function (req, res) {
      req.render('profile-edit', { id: req.params.id }); 
    })
    app.get('/admin', user.is('admin'), function (req, res) {
      res.render('admin');
    }
    

提交回复
热议问题