From 1bcfd773b1db5e25953e66d96ede27658d37dc05 Mon Sep 17 00:00:00 2001 From: Sergio Betanzos Date: Fri, 7 May 2021 12:44:08 +0200 Subject: [PATCH] B #5380: Fix fireedge when session expires (#1189) (cherry picked from commit d7fe6f7e3d05fb9dd2830ca17e857b3e509a4892) --- src/fireedge/src/client/components/HOC/MainLayout.js | 8 +++++--- src/fireedge/src/client/components/Sidebar/index.js | 2 +- src/fireedge/src/client/constants/translates.js | 1 + src/fireedge/src/client/hooks/useAuth.js | 7 +++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/fireedge/src/client/components/HOC/MainLayout.js b/src/fireedge/src/client/components/HOC/MainLayout.js index cb81267aee..6cf2b354db 100644 --- a/src/fireedge/src/client/components/HOC/MainLayout.js +++ b/src/fireedge/src/client/components/HOC/MainLayout.js @@ -39,14 +39,16 @@ const MainLayout = ({ endpoints, children }) => { isLoginInProcess, getAuthInfo, authUser, - firstRender + firstRender, + isLoading } = useAuth() useEffect(() => { - if (isLogged && !isLoginInProcess) { + console.log({ isLoading }) + if (isLogged && !isLoginInProcess && !isLoading) { getAuthInfo() } - }, [isLogged, isLoginInProcess]) + }, [isLogged, isLoginInProcess, pathname]) const { authenticated } = findRouteByPathname(ENDPOINTS, pathname) const authRoute = Boolean(authenticated) diff --git a/src/fireedge/src/client/components/Sidebar/index.js b/src/fireedge/src/client/components/Sidebar/index.js index 92f459347a..1423aeee18 100644 --- a/src/fireedge/src/client/components/Sidebar/index.js +++ b/src/fireedge/src/client/components/Sidebar/index.js @@ -85,7 +85,7 @@ const Sidebar = memo(({ endpoints }) => { ) -}, (prev, next) => prev.endpoints === next.endpoints) +}, (prev, next) => prev.endpoints.length === next.endpoints.length) Sidebar.propTypes = { endpoints: PropTypes.array diff --git a/src/fireedge/src/client/constants/translates.js b/src/fireedge/src/client/constants/translates.js index 393d35aeb2..dcf198c38e 100644 --- a/src/fireedge/src/client/constants/translates.js +++ b/src/fireedge/src/client/constants/translates.js @@ -35,6 +35,7 @@ module.exports = { Token2FA: '2FA Token', KeepLoggedIn: 'Keep me logged in', Credentials: 'Credentials', + SessionExpired: 'Sorry, your session has expired', /* errors */ CannotConnectOneFlow: 'Cannot connect to OneFlow server', diff --git a/src/fireedge/src/client/hooks/useAuth.js b/src/fireedge/src/client/hooks/useAuth.js index 6e9e9edc8c..7b0d6e40be 100644 --- a/src/fireedge/src/client/hooks/useAuth.js +++ b/src/fireedge/src/client/hooks/useAuth.js @@ -1,7 +1,7 @@ import { useCallback, useEffect } from 'react' import { useSelector, useDispatch, shallowEqual } from 'react-redux' -import { JWT_NAME, FILTER_POOL, ONEADMIN_ID, TIME_HIDE_LOGO } from 'client/constants' +import { T, JWT_NAME, FILTER_POOL, ONEADMIN_ID, TIME_HIDE_LOGO } from 'client/constants' import { storage, findStorageData, removeStoreData, fakeDelay } from 'client/utils' import * as serviceAuth from 'client/services/auth' @@ -84,7 +84,10 @@ const useAuth = () => { .then(() => dispatch(updateSetting)) .then(() => serviceOne.getGroups()) .then(groups => dispatch(setGroups(groups))) - .catch(err => dispatch(failureAuth({ error: err }))) + .catch(() => { + dispatch(logoutRequest()) + dispatch(failureAuth({ error: T.SessionExpired })) + }) }, [dispatch, JWT_NAME, authUser]) const setPrimaryGroup = useCallback(