summaryrefslogtreecommitdiff
path: root/server/providers/util
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/util
parent84b45cd6b11347e66437cd92dc20372d0abd6eb9 (diff)
downloadlocchat-95961c5a14d07c79ffae0f0f36b58ca7c3ea521b.tar.gz
locchat-95961c5a14d07c79ffae0f0f36b58ca7c3ea521b.zip
auth guard update
Diffstat (limited to 'server/providers/util')
-rw-r--r--server/providers/util/guard.util.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/server/providers/util/guard.util.ts b/server/providers/util/guard.util.ts
new file mode 100644
index 0000000..64d4627
--- /dev/null
+++ b/server/providers/util/guard.util.ts
@@ -0,0 +1,17 @@
+import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
+import { Reflector } from '@nestjs/core';
+import { SKIP_KEY } from 'server/decorators/skip.decorator';
+import { Class } from 'server/dto/class.dto';
+
+@Injectable()
+export class GuardUtil {
+ constructor(private reflector: Reflector) {}
+
+ public shouldSkip(guard: CanActivate, context: ExecutionContext) {
+ const skippedGuards = this.reflector.getAllAndOverride<Class<CanActivate>[]>(SKIP_KEY, [
+ context.getHandler(),
+ context.getClass(),
+ ]);
+ return !!(skippedGuards && skippedGuards.find((SkippedGuard) => guard instanceof SkippedGuard));
+ }
+}