
const roles = require('../config/role');

function checkPermission(permission) {
  return (req, res, next) => {
    console.log("here again:",req.user)
    const userPermission = req.user.permission; // Assume `role` is attached to `req.user` after authentication


    console.log("here again:",userPermission)
    if (!userPermission.includes(permission)) {
      return res.status(403).json({ message: 'Access Denied: Insufficient permissions' });
    }
    next();
  };
}


module.exports = { checkPermission };
