From e192dcdb0534894d0d672d272eea13e077e9f735 Mon Sep 17 00:00:00 2001 From: noahspannbauer Date: Tue, 24 Sep 2024 08:58:43 -0500 Subject: [PATCH] Feature/8 add optional auth guard (#9) * adding optional auth to guard * adding optional auth to guard --- libs/modules/src/auth/auth.gaurd.ts | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/modules/src/auth/auth.gaurd.ts b/libs/modules/src/auth/auth.gaurd.ts index 81bb84c..5313256 100644 --- a/libs/modules/src/auth/auth.gaurd.ts +++ b/libs/modules/src/auth/auth.gaurd.ts @@ -15,8 +15,11 @@ export class AuthGuard extends PassportAuthGuard('azure-ad') implements CanActiv 'isPublic', context.getHandler() ); + const req = context.switchToHttp().getRequest(); + const authHeader = req.headers.authorization; + const token = authHeader && authHeader.split(' ')[1]; - if (isPublic) { + if (isPublic && !token) { return true; } diff --git a/package.json b/package.json index ed3cba0..80cd8e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@noahspan/noahspan-modules", - "version": "0.3.9", + "version": "0.4.0", "description": "", "author": "", "license": "UNLICENSED",