summaryrefslogtreecommitdiff
path: root/server/providers/guards/auth.guard.ts
diff options
context:
space:
mode:
authorJoseph Ditton <jditton.atomic@gmail.com>2021-12-03 14:46:44 -0700
committerJoseph Ditton <jditton.atomic@gmail.com>2021-12-03 14:46:44 -0700
commit95961c5a14d07c79ffae0f0f36b58ca7c3ea521b (patch)
tree7d20b3e6f44d54a4c1c24b07689bf5e036e104fc /server/providers/guards/auth.guard.ts
parent84b45cd6b11347e66437cd92dc20372d0abd6eb9 (diff)
downloadlocchat-95961c5a14d07c79ffae0f0f36b58ca7c3ea521b.tar.gz
locchat-95961c5a14d07c79ffae0f0f36b58ca7c3ea521b.zip
auth guard update
Diffstat (limited to 'server/providers/guards/auth.guard.ts')
-rw-r--r--server/providers/guards/auth.guard.ts19
1 files changed, 6 insertions, 13 deletions
diff --git a/server/providers/guards/auth.guard.ts b/server/providers/guards/auth.guard.ts
index 8c03ad8..722094b 100644
--- a/server/providers/guards/auth.guard.ts
+++ b/server/providers/guards/auth.guard.ts
@@ -1,24 +1,17 @@
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
import { JwtService } from '../services/jwt.service';
-import { SKIP_KEY } from 'server/decorators/skip.decorator';
-import { Reflector } from '@nestjs/core';
-import { Class } from 'server/dto/class.dto';
+import { GuardUtil } from '../util/guard.util';
@Injectable()
export class AuthGuard implements CanActivate {
- constructor(private reflector: Reflector, private jwtService: JwtService) {}
+ constructor(private guardUtil: GuardUtil, private jwtService: JwtService) {}
canActivate(context: ExecutionContext) {
- const skippedGuards = this.reflector.getAllAndOverride<Class<CanActivate>[]>(SKIP_KEY, [
- context.getHandler(),
- context.getClass(),
- ]);
- if (skippedGuards) {
- const skippedGuard = skippedGuards.find((guard) => this instanceof guard);
- if (skippedGuard) {
- return true;
- }
+ // Handlers and Controllers can both skip this guard in the event that
+ if (this.guardUtil.shouldSkip(this, context)) {
+ return true;
}
+
const req = context.switchToHttp().getRequest();
const authHeader = req.headers.authorization;
if (!authHeader) return false;