From 377f820e708af54725447e9f1e57d65cb90146e7 Mon Sep 17 00:00:00 2001 From: dudiiiiiiii Date: Thu, 17 Oct 2024 11:23:40 +0200 Subject: [PATCH] better comments and easier boolean logic --- src/services/AuthService.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/services/AuthService.tsx b/src/services/AuthService.tsx index edc0643a..54ca6ed9 100644 --- a/src/services/AuthService.tsx +++ b/src/services/AuthService.tsx @@ -194,12 +194,20 @@ const Auth = ({ children }: GenericContextProviderProps) => { ); }; - if (!initialized || !keycloak.authenticated) { - if (initialized && !keycloak.authenticated) { + if (!initialized) { + // keycloak authentication system not initilized (working in demo mode or keycloak not to handle authentication and authorization) + // skipping futher checks (for example: to ask backend if the keycloak token is OK + return; + } else { + // keycloak authentication is initilized, so it makes sense to check if user is authenticated in keycloak + if (!keycloak.authenticated) { + // user not authenticated, forcing logout from yaptide app logout(); - } - return; + // skipping futher checks (for example: to ask backend if the keycloak token is OK + return; + } + // user authenticated, we proceed with further checks } checkPlgridAccessServices(keycloak.tokenParsed)