Feathersjspipe理员angular色(或用auth检查羽毛中间件)

我有一个愚蠢的问题与feathersjs auth钩(或其他)。 这是我的代码评论:

app.get('/admin', function (req, res) { // i'd like to check here if (req.connection.isAdmin) then render page res.render('admin/admin.html', { title: 'admin' }) }); 

我无法find哪里我可以实现用户身份validation的钩子chek用户的pipe理angular色。 我怎样才能做到这一点?

你应该可以使用我在其他问题中发布的例子: 羽毛Js限制服务器端的页面访问

在你的情况下,你需要做一些逻辑来看看用户是否是pipe理员。 默认情况下,羽毛给你的JWT标记只包含userId 。 您可以检索用户logging来检查用户是否是pipe理员。

下面是一个你要在jwt.verify块中放置的例子:

 jwt.verify(token, secret, function(err, decoded) { if (err) { return res.status(401).send('You are not authorized to view that page.'); } app.service('users') .get(decoded.id) // Or _id if you're using MongoDB .then(user => { if (user.isAdmin) { res.render('admin/admin.html', { title: 'admin' }) } else { return res.status(401).send('You are not authorized to view that page.'); } }) }); 

feathers-authentication的下一个版本中,可以将值添加到服务器上的JWT,因此,对于pipe理员,您可以将isAdmin属性添加到JWT有效内容中。 一旦预发布版本发布,这将是相当微不足道的。 在此之前,上述可能是最好的方法。