Untitled
unknown
typescript
3 years ago
538 B
9
Indexable
import { Request, Response, NextFunction } from 'express';
import { PayloadRequest } from '../utils/config';
import { SUPER_ADMINS } from '../utils/config';
export const isAdmin = (req: Request, res: Response, next: NextFunction) => {
try {
const userPayload = (req as PayloadRequest).userPayload;
if (SUPER_ADMINS.includes(userPayload.personalNumber) || userPayload.isAdmin) {
next();
return;
}
throw new Error('You must be an admin');
} catch (error) {
res.statusCode = 400;
next(error);
}
};
Editor is loading...