aboutsummaryrefslogtreecommitdiff
path: root/src/auth.ts
diff options
context:
space:
mode:
authorTom Harley2018-03-03 14:18:11 +0000
committerTom Harley2018-03-03 14:18:11 +0000
commit11776b9665c1bc3e49cf602dfa069294a490d5fd (patch)
treeabed539acf263e6e5d45c82752de0c6d37a068fb /src/auth.ts
parentMerge branch 'trh/gets' into trh/payload-checker (diff)
downloadmedicine-11776b9665c1bc3e49cf602dfa069294a490d5fd.tar.gz
medicine-11776b9665c1bc3e49cf602dfa069294a490d5fd.zip

Fix minor things

Diffstat (limited to 'src/auth.ts')
-rw-r--r--src/auth.ts27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/auth.ts b/src/auth.ts
index d5969c5..b40cddb 100644
--- a/src/auth.ts
+++ b/src/auth.ts
@@ -51,7 +51,9 @@ export class AuthRouter {
if (err) { throw err; }
if (!user) {
- next(new RequestError(400, 'invalid_grant', 'Incorrect authentication details'));
+ next(new RequestError(
+ 400, 'invalid_grant', 'Incorrect authentication details'
+ ));
}
}
);
@@ -73,25 +75,34 @@ export class AuthRouter {
}
// Handle error if user is unauthorised
- public unauthorisedErr(err: Error, req: Request, res: Response, next: NextFunction): void {
+ public unauthorisedErr(
+ err: Error, req: Request, res: Response, next: NextFunction
+ ): void {
if (err.name === 'UnauthorizedError') {
- next(new RequestError(401, 'not_authorised', 'user does not have correct authorisation to complete task'));
+ next(new RequestError(
+ 401, 'not_authorised',
+ 'user does not have correct authorisation for task'
+ ));
}
next();
}
- //middleware to check privileges - admin
- public isAdmin(req: Request, res: Response, next: NextFunction) {
+ // Middleware to check privileges - admin
+ public isAdmin(req: Request, res: Response, next: NextFunction): void {
if (!req.user.admin) {
- next(new RequestError(401, 'not_authorised', 'user is not authorised to perform task'));
+ next(new RequestError(
+ 401, 'not_authorised',
+ 'user is not authorised to perform task'
+ ));
+ return;
}
next();
}
// Configure local strategy to use with passport-js.
- private configStrategy() {
+ private configStrategy(): void {
// tslint:disable-next-line:typedef
- passport.use(new Strategy( async(username, password, done) => {
+ passport.use(new Strategy( async(username, password, done) => {
const user: User | null = await User.findOne({
where: {
username