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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -