Init
This commit is contained in:
commit
0029086b3f
148 changed files with 19047 additions and 0 deletions
19
packages/api/src/middleware/is-admin.ts
Normal file
19
packages/api/src/middleware/is-admin.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { NextFunction, Response } from 'express';
|
||||
import { isAdminSub } from '../baseblocks/admin/admin.service';
|
||||
import { RequestContext } from '../util/request-context.type';
|
||||
|
||||
export const isAdmin = async (
|
||||
req: RequestContext,
|
||||
res: Response,
|
||||
next: NextFunction,
|
||||
) => {
|
||||
const userSub = req.currentUserSub;
|
||||
const isAdmin = await isAdminSub(userSub);
|
||||
if (!isAdmin) {
|
||||
res.status(403).json({
|
||||
error: 'User does not have permission',
|
||||
});
|
||||
return;
|
||||
}
|
||||
next();
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue