I'm a fresher and I got a task that In our project, we have 7 roles i.e Admin Insurer Investor Customer Moderator Lender Agent Admin can access all API but some of the API can access by Admin and moderator or Admin or Insurer or Admin or Investor and so on. There might be 30+ permutations and combinations. Is there any simple way to do that? Any dynamic way to do please help. The code I wrote this is middleware const isUser = (req, res, next) => { if (req.user && req.roles[0].toUpperCase == 'USER') { next(); } else { return res.status(401).send({ message: `You don't have correct access`, }); } }; const isInvestor = (req, res, next) => { if (req.user && req.roles[0].toUpperCase == 'INVESTOR') { next(); } else { return res.status(401).send({ message: `You don't have correct access`, }); } }; const isModerator = (req, res, next) => { if (req.user && req.roles[0].toUpperCase == 'MODERATOR') { next(); } else { return res.status(401).send({ message: `You don't have correct access`, }); } }; const isAdmin = (req, res, next) => { if (req.user && req.roles[0] == 'ADMIN') { next(); } else { return res.status(401).send({ message: `You don't have correct access`, }); } }; const isInsurer = (req, res, next) => { if (req.user && req.roles[0].toUpperCase == 'INSURER') { next(); } else { return res.status(401).send({ message: `You don't have correct access`, }); } }; const isNominee = (req, res, next) => { if (req.user && req.roles[0].toUpperCase == 'NOMINEE') { next(); } else { return res.status(401).send({ message: `You don't have correct access`, }); } }; const isAgent = (req, res, next) => { if (req.user && req.roles[0].toUpperCase == 'AGENT') { next(); } else { return res.status(401).send({ message: `You don't have correct access`, }); } }; const isLender = (req, res, next) => { if (req.user && req.roles[0].toUpperCase == 'LENDER') { next(); } else { return res.status(401).send({ message: `You don't have correct access`, }); } }; const isAdminOrInvestor = (req, res, next) => { if (req.user && (req.roles[0].toUpperCase == 'INVESTOR'||req.roles[0].toUpperCase == 'ADMIN')) { next(); } else { return res.status(401).send({ message: `You don't have correct access`, }); } }; const isAdminOrInsurer = (req, res, next) => { if (req.user && (req.roles[0].toUpperCase == 'INSURER'||req.roles[0].toUpperCase == 'ADMIN')) { next(); } else { return res.status(401).send({ message: `You don't have correct access`, }); } }; Continue reading...