add moderator role (#1419)

This commit is contained in:
notmd
2023-02-10 18:18:48 +09:00
committed by GitHub
parent 1439dd69b5
commit 7a0bfa2d68
18 changed files with 95 additions and 32 deletions
+14
View File
@@ -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 };