mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-08-17 11:13:32 +08:00
add moderator role (#1419)
This commit is contained in:
@@ -32,4 +32,18 @@ const withRole = (role: Role, handler: (arg0: NextApiRequest, arg1: NextApiRespo
|
||||
};
|
||||
};
|
||||
|
||||
export const withAnyRole = (
|
||||
roles: Role[],
|
||||
handler: (arg0: NextApiRequest, arg1: NextApiResponse, token: JWT) => void
|
||||
) => {
|
||||
return async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const token = await getToken({ req });
|
||||
if (!token || roles.every((role) => token.role !== role)) {
|
||||
res.status(403).end();
|
||||
return;
|
||||
}
|
||||
return handler(req, res, token);
|
||||
};
|
||||
};
|
||||
|
||||
export { withoutRole, withRole };
|
||||
|
||||
Reference in New Issue
Block a user