From 7a06fd6eac864972a4acc15078627f0ffc20c1f9 Mon Sep 17 00:00:00 2001 From: Hafeez Date: Thu, 1 Mar 2018 19:26:35 +0000 Subject: added middleware to check if admin --- src/auth.ts | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/auth.ts b/src/auth.ts index 937f20f..3feac5d 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -83,6 +83,14 @@ export class AuthRouter { next(); } + //middleware to check privileges - admin + public isAdmin(req: Request, res: Response, next: NextFunction) { + if (!req.user.admin) { + next(new RequestError(401, 'not_authorised', 'user is not authorised to perform task')); + } + next(); + } + // Configure local strategy to use with passport-js. private configStrategy() { passport.use(new localStrategy( (username, password, done) => { -- cgit v1.2.1