Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Changed
- `src/auth/middleware.js`: `authorize()` now accepts an array of roles for multi-role access control (Fixes #9)

## [1.0.0] - 2026-03-20
### Added
- Initial Express.js API with health, users endpoints
Expand Down
4 changes: 3 additions & 1 deletion src/auth/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ function authenticate(req, res, next) {

/**
* authorize — simple role-based access control.
* Supports array of roles for multi-role checks.
*/
function authorize(role) {
const allowed = Array.isArray(role) ? role : [role];
return (req, res, next) => {
if (!req.user) {
return res.status(401).json({ error: 'Not authenticated' });
}
if (req.user.role !== role) {
if (!allowed.includes(req.user.role)) {
return res.status(403).json({ error: 'Insufficient permissions' });
}
next();
Expand Down