From a1147ff808a811ecd74cfa7803769ec7739fc9fd Mon Sep 17 00:00:00 2001 From: "ajithkumar.s" Date: Tue, 9 Jul 2024 13:42:25 +0530 Subject: [PATCH 1/2] fix: set state issue fix in app layout --- src/components/layouts/AppLayout.tsx | 5 ----- src/features/app/slice.ts | 2 -- src/features/app/types.ts | 4 ---- src/services/UserService.ts | 18 +++++++++--------- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/components/layouts/AppLayout.tsx b/src/components/layouts/AppLayout.tsx index 69402650..6c8d6634 100644 --- a/src/components/layouts/AppLayout.tsx +++ b/src/components/layouts/AppLayout.tsx @@ -20,8 +20,6 @@ import { Box } from '@mui/material'; import { useGetPermissionsQuery, useGetUseCasesQuery } from '../../features/app/apiSlice'; -import { setLoggedInUser } from '../../features/app/slice'; -import { useAppDispatch } from '../../features/store'; import Nav from '../Nav'; import Sidebar from '../sidebar'; @@ -30,9 +28,6 @@ export default function AppLayout(props: any) { useGetUseCasesQuery({}); useGetPermissionsQuery({}); - const dispatch = useAppDispatch(); - dispatch(setLoggedInUser(props.loggedUser)); - return ( diff --git a/src/features/app/slice.ts b/src/features/app/slice.ts index 3c7d3f20..65d20175 100644 --- a/src/features/app/slice.ts +++ b/src/features/app/slice.ts @@ -32,8 +32,6 @@ const initialState: IAppSlice = { company: '', bpn: '', tenant: '', - token: '', - parsedToken: {}, }, permissions: [], useCases: [], diff --git a/src/features/app/types.ts b/src/features/app/types.ts index b3016aee..116189ac 100644 --- a/src/features/app/types.ts +++ b/src/features/app/types.ts @@ -17,8 +17,6 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -import { KeycloakTokenParsed } from 'keycloak-js'; - import { IAlertColors } from '../notifiication/types'; export interface IUser { userName: string; @@ -27,8 +25,6 @@ export interface IUser { company: string; bpn: string; tenant: string; - token: string; - parsedToken: KeycloakTokenParsed; } export interface IAppSlice { pageLoading: boolean; diff --git a/src/services/UserService.ts b/src/services/UserService.ts index 7df5d3db..a7d5b9d9 100644 --- a/src/services/UserService.ts +++ b/src/services/UserService.ts @@ -17,10 +17,11 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ - import Keycloak from 'keycloak-js'; +import { setLoggedInUser } from '../features/app/slice'; import { IUser } from '../features/app/types'; +import { store } from '../features/store'; import { getCentralIdp, getClientId, getClientRealm } from './EnvironmentService'; const keycloakConfig: Keycloak.KeycloakConfig = { @@ -66,34 +67,33 @@ const getLoggedUser = () => ({ company: getCompany(), bpn: getBpn(), tenant: getTenant(), - token: getToken(), - parsedToken: getParsedToken(), }); const update = () => { - KC.updateToken(50) + KC.updateToken(600) .then((refreshed: boolean) => { - if (refreshed) console.log(`${getUsername()} token refreshed ${refreshed}`); + console.log(`${getUsername()} token refreshed ${refreshed}`); }) .catch(() => { console.log(`${getUsername()} token refresh failed`); }); }; -const initKeycloak = (onAuthenticatedCallback: (loggedUser: IUser) => unknown) => { +const initKeycloak = (onAuthenticatedCallback: (loggedUser: IUser) => void) => { KC.init({ onLoad: 'login-required', pkceMethod: 'S256', + enableLogging: true, }) .then(authenticated => { if (authenticated) { onAuthenticatedCallback(getLoggedUser()); - setInterval(update, 50000); + store.dispatch(setLoggedInUser(getLoggedUser())); } else { - doLogin(); + console.log(`${getUsername()} authentication failed`); } }) - .catch(console.error); + .catch(err => console.log(err)); }; KC.onTokenExpired = () => { From 5cece1a0d4d081f92a3ec6bccd46bb8d0e35990b Mon Sep 17 00:00:00 2001 From: "ajithkumar.s" Date: Tue, 9 Jul 2024 13:51:22 +0530 Subject: [PATCH 2/2] copyright headers updated --- src/services/UserService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/UserService.ts b/src/services/UserService.ts index a7d5b9d9..f30f1d51 100644 --- a/src/services/UserService.ts +++ b/src/services/UserService.ts @@ -1,6 +1,6 @@ /******************************************************************************** - * Copyright (c) 2021,2022,2023 T-Systems International GmbH - * Copyright (c) 2022,2023 Contributors to the Eclipse Foundation + * Copyright (c) 2022,2024 T-Systems International GmbH + * Copyright (c) 2022,2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership.