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

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -