From aa9e0536a76f3083150f6444af40024ce06fc6d1 Mon Sep 17 00:00:00 2001 From: Gabriel Rosa Date: Fri, 17 Feb 2023 09:55:10 -0300 Subject: [PATCH] FIX: tests --- src/authentication/authentication.guard.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/authentication/authentication.guard.ts b/src/authentication/authentication.guard.ts index f97bdfe..7e938b0 100644 --- a/src/authentication/authentication.guard.ts +++ b/src/authentication/authentication.guard.ts @@ -54,11 +54,14 @@ export class AuthenticationGuard >(AUTH_FUNCTION_KEY, [ctx.getClass(), ctx.getHandler()]); const mustBeAuthenticated = authFunctions.length > 0; - if (!mustBeAuthenticated) return true; - const request = ctx.switchToHttp().getRequest(); const accessToken = this.validateToken(request, mustBeAuthenticated); + if (!mustBeAuthenticated) { + // no need to be authenticated + return true; + } + if (!accessToken) { // couldn't load valid token throw new ErrorBuilder(ErrorCodes.AUTH.UNAUTHORIZED);