aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHafeez2018-03-01 19:26:35 +0000
committerHafeez2018-03-01 19:26:35 +0000
commit7a06fd6eac864972a4acc15078627f0ffc20c1f9 (patch)
treef91a16acf1ada37f9111b7ff98529c6437d9f6eb
parentadded new request error objects (diff)
downloadmedicine-7a06fd6eac864972a4acc15078627f0ffc20c1f9.tar.gz
medicine-7a06fd6eac864972a4acc15078627f0ffc20c1f9.zip

added middleware to check if admin

-rw-r--r--src/auth.ts8
1 files changed, 8 insertions, 0 deletions
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) => {