diff --git a/src/guards/groups.guards.ts b/src/guards/groups.guards.ts index 3b9ae9d2fb938bb8211dced2945085ea3e110039..7028262312a50b04a08a6ac5ac9abf607f4d8a64 100644 --- a/src/guards/groups.guards.ts +++ b/src/guards/groups.guards.ts @@ -1,4 +1,4 @@ -import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common'; +import { Injectable, CanActivate, ExecutionContext, Logger } from '@nestjs/common'; import { Reflector } from '@nestjs/core'; import { ConfigService } from '../configuration/config.service'; @@ -7,6 +7,7 @@ export class GroupsGuard implements CanActivate { constructor(private readonly reflector: Reflector, private configService: ConfigService) {} canActivate(context: ExecutionContext): boolean { + Logger.log('[+] GroupMiddleware'); // We get the groups specified on the endpoint with the @Groups annotation // We need then to get the real group names associated to those keys from the config file const groups = this.reflector.get<string[]>('groups', context.getHandler()).map((e) => { @@ -23,10 +24,14 @@ export class GroupsGuard implements CanActivate { const groupHeader = request.headers[this.configService.config.groupHeader]; if (!groupHeader) { + Logger.log(' [-] no group header'); return false; } const consumerGroups = groupHeader.split(',').map(e => e.trim()); + + Logger.log(` [-] consumer groups: ${consumerGroups}`); + const hasGroup = () => consumerGroups.some((group) => groups.includes(group)); return consumerGroups && hasGroup();