javascript - Can this way auth user with role? -


i don't want use additional middleware connect-roles, sufficient enough perform authorization?

function authwithrole(role) {     return (req, res, next) => {         // check login , role.         if (req.isauthenticated() &&             _.indexof(req.user.roles, role) > -1) {             return next();         } else {             res.status(404).send('<h1>404 not found!</h1>');         }     } }  router.all('/*', authwithrole("admin")); 

could provide simpler , more practical example performing authorization?

yes. can perform authorization way.

this simple gets without using modules.

you should refactor:

router.all('/*', authwithrole("admin")); 

to:

router.all('*', authwithrole("admin")); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -