fastcheck/server/src/middleware/role.middleware.ts
2026-04-08 13:58:46 -04:00

15 lines
394 B
TypeScript

import { Request, Response, NextFunction } from 'express';
export const authorize = (roles: string[]) => {
return (req: Request, res: Response, next: NextFunction) => {
if (!req.user) {
return res.status(401).json({ message: 'Unauthorized' });
}
if (!roles.includes(req.user.role)) {
return res.status(403).json({ message: 'Forbidden' });
}
next();
};
};