Verifying roles & authentication with Passport.js

前端 未结 3 1139
慢半拍i
慢半拍i 2021-02-01 22:58

So I\'d like to make some routes in an API that will show different data based on the user role, defined in MongoDB. Here\'s a sampling of what I have right now, it works...

3条回答
  •  别跟我提以往
    2021-02-01 23:45

    The solution is to limit the content in the view rather than the route.

    router.get('/test', authenticationMiddleware, function(req, res){
        var premiumFlag = req.user.role;
        res.send('premiumontent', {role: premiumFlag});
    });
    

    premiumContent.jade

    p This content is visible to all users
    
    - if role === "premium"
        p this content is only visible to premium users
    

提交回复
热议问题