LocChat/server/providers/util/guard.util.ts
2021-12-03 14:46:44 -07:00

18 lines
644 B
TypeScript

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));
}
}