feat: Implement role-based access control middleware and update documentation
Some checks are pending
Docker Test / test (push) Waiting to run

This commit is contained in:
BibaBot Jarvis 2026-03-16 03:06:38 +00:00
parent 7c9862a08a
commit 30bd7f0214
4 changed files with 65 additions and 2 deletions

View file

@ -0,0 +1,20 @@
/**
* Middleware to check if the user has the required role(s)
* @param {string[]} allowedRoles - Array of roles allowed to access the endpoint
* @returns {function} Express middleware function
*/
export const requireRole = (allowedRoles) => {
return (req, res, next) => {
const userRole = req.user?.role;
if (!userRole) {
return res.status(401).json({ error: 'Unauthorized: Missing role claim' });
}
if (!allowedRoles.includes(userRole)) {
return res.status(403).json({ error: 'Forbidden: Insufficient permissions' });
}
next();
};
};