Add custom error msg param for role auth
This commit is contained in:
parent
6ba483f0b7
commit
1af696b39c
1 changed files with 2 additions and 2 deletions
|
|
@ -3,10 +3,10 @@ import HttpError from "../interfaces/http-error";
|
|||
import HttpStatus from "../interfaces/http-status";
|
||||
import { RequestWithUser } from "./user";
|
||||
|
||||
export function authRole(role: string) {
|
||||
export function authRole(role: string, errorMessage = "คุณไม่มีสิทธิในการเข้าถึงทรัพยากรดังกล่าว") {
|
||||
return (req: RequestWithUser, _res: express.Response, next: express.NextFunction) => {
|
||||
if (!req.user.role.includes(role)) {
|
||||
throw new HttpError(HttpStatus.FORBIDDEN, "คุณไม่มีสิทธิในการเข้าถึงทรัพยากรดังกล่าว");
|
||||
throw new HttpError(HttpStatus.FORBIDDEN, errorMessage);
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue