From 6cd3f2773d2f1efbf4f578eb89f9176b4245a857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Matias=CC=8Cko?= Date: Fri, 1 Sep 2023 13:07:19 +0200 Subject: [PATCH] show InitializedByAnother when compareOwners fails --- .../RemoteClientsPage/RemoteClientsPage.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/http-gateway/web/src/containers/RemoteClients/RemoteClientsPage/RemoteClientsPage.tsx b/http-gateway/web/src/containers/RemoteClients/RemoteClientsPage/RemoteClientsPage.tsx index e275b4bd2..d4d605132 100644 --- a/http-gateway/web/src/containers/RemoteClients/RemoteClientsPage/RemoteClientsPage.tsx +++ b/http-gateway/web/src/containers/RemoteClients/RemoteClientsPage/RemoteClientsPage.tsx @@ -72,17 +72,17 @@ const RemoteClientsPage: FC = (props) => { [wellKnownConfig, clientData] ) - const compareOwners = useCallback((wellKnownConfig?: WellKnownConfigType) => { + const unCompareOwners = useCallback((wellKnownConfig?: WellKnownConfigType) => { const userData = clientAppSettings.getUserData() - if (userData && wellKnownConfig) { - if (!wellKnownConfig.isInitialized) { - return true - } + if (!wellKnownConfig?.isInitialized) { + return false + } + if (userData && wellKnownConfig) { const parsedData = jwtDecode(userData.access_token) const ownerId = get(parsedData, wellKnownConfig?.remoteProvisioning?.jwtOwnerClaim as string, '') - if (ownerId === wellKnownConfig?.owner) { + if (ownerId !== wellKnownConfig?.owner) { return true } } @@ -91,22 +91,22 @@ const RemoteClientsPage: FC = (props) => { }, []) useEffect(() => { - if (!compareOwners(wellKnownConfig) && !initializedByAnother) { + if (wellKnownConfig && unCompareOwners(wellKnownConfig) && !initializedByAnother) { setInitializedByAnother(true) } - }, [compareOwners, initializedByAnother, wellKnownConfig]) + }, [unCompareOwners, initializedByAnother, wellKnownConfig]) const unauthorizedCallback = useCallback(() => { setSuspectedUnauthorized(true) reFetchConfig().then((newWellKnownConfig: WellKnownConfigType) => { - if (compareOwners(newWellKnownConfig)) { + if (!unCompareOwners(newWellKnownConfig)) { setSuspectedUnauthorized(false) } else { setInitializedByAnother(true) } }) - }, [compareOwners, reFetchConfig]) + }, [unCompareOwners, reFetchConfig]) const contextValue = useMemo( () => ({ @@ -127,7 +127,7 @@ const RemoteClientsPage: FC = (props) => { return } else { clientAppSettings.setWellKnowConfig(wellKnownConfig) - clientAppSettings.setUseToken(compareOwners(wellKnownConfig) && clientData.authenticationMode === DEVICE_AUTH_MODE.X509) + clientAppSettings.setUseToken(!unCompareOwners(wellKnownConfig) && clientData.authenticationMode === DEVICE_AUTH_MODE.X509) if (wellKnownConfig.remoteProvisioning) { clientAppSettings.setWebOAuthConfig({