summaryrefslogtreecommitdiff
path: root/server/providers/guards/auth.guard.ts
diff options
context:
space:
mode:
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;