14 lines
553 B
TypeScript
14 lines
553 B
TypeScript
|
|
import * as express from "express";
|
||
|
|
import HttpError from "../interfaces/http-error";
|
||
|
|
import HttpStatus from "../interfaces/http-status";
|
||
|
|
import { RequestWithUser } from "./user";
|
||
|
|
|
||
|
|
export function authRole(role: string) {
|
||
|
|
return (req: RequestWithUser, _res: express.Response, next: express.NextFunction) => {
|
||
|
|
if (!req.user.role.includes(role)) {
|
||
|
|
throw new HttpError(HttpStatus.FORBIDDEN, "คุณไม่มีสิทธิในการเข้าถึงทรัพยากรดังกล่าว");
|
||
|
|
}
|
||
|
|
next();
|
||
|
|
};
|
||
|
|
}
|