From 2ee928a2e3ffc86bed8fff34b683d1d997634096 Mon Sep 17 00:00:00 2001 From: Ebube Date: Mon, 17 Apr 2023 21:33:39 +0100 Subject: [PATCH 1/2] logout timeout --- .env | 4 +++- src/app/modules/auth/core/Auth.tsx | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 9cf80df..a8ff12d 100644 --- a/.env +++ b/.env @@ -16,4 +16,6 @@ REACT_APP_PREVIEW_DOCS_URL=https://preview.keenthemes.com/metronic8/react/docs REACT_APP_THEME_API_URL=https://preview.keenthemes.com/theme-api/api REACT_APP_TERMS_LINK='https://www.float.sg/terms' REACT_APP_CONTACT_LINK='https://www.float.sg/contact' -REACT_APP_ABOUT_LINK='https://www.float.sg/about' \ No newline at end of file +REACT_APP_ABOUT_LINK='https://www.float.sg/about' + +REACT_APP_LOGOUT_SESSION_TIMEOUT=300000 \ No newline at end of file diff --git a/src/app/modules/auth/core/Auth.tsx b/src/app/modules/auth/core/Auth.tsx index 930131c..070cf01 100644 --- a/src/app/modules/auth/core/Auth.tsx +++ b/src/app/modules/auth/core/Auth.tsx @@ -8,6 +8,7 @@ import { Dispatch, SetStateAction, } from 'react' +import {useLocation} from 'react-router-dom' import {LayoutSplashScreen} from '../../../../_res/layout/core' import {AuthModel, UserModel} from './_models' import * as authHelper from './AuthHelpers' @@ -61,6 +62,7 @@ const AuthProvider: FC = ({children}) => { } const AuthInit: FC = ({children}) => { + const {pathname} = useLocation() const {auth, logout, setCurrentUser} = useAuth() const didRequest = useRef(false) const [showSplashScreen, setShowSplashScreen] = useState(true) @@ -95,8 +97,17 @@ const AuthInit: FC = ({children}) => { logout() setShowSplashScreen(false) } + + // adding a timeout for 5mins + const logOutSession = setTimeout(() => { + logout() + }, Number(process.env.REACT_APP_LOGOUT_SESSION_TIMEOUT)) // eslint-disable-next-line - }, []) + + return (() => { + clearInterval(logOutSession) + }) + }, [pathname]) return showSplashScreen ? : <>{children} } -- 2.34.1 From 0001fe5d595b75bc09e01dc688188efa0bb71aa5 Mon Sep 17 00:00:00 2001 From: Ebube Date: Mon, 17 Apr 2023 21:35:22 +0100 Subject: [PATCH 2/2] adjusted line --- src/app/modules/auth/core/Auth.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/modules/auth/core/Auth.tsx b/src/app/modules/auth/core/Auth.tsx index 070cf01..4351b7f 100644 --- a/src/app/modules/auth/core/Auth.tsx +++ b/src/app/modules/auth/core/Auth.tsx @@ -102,11 +102,11 @@ const AuthInit: FC = ({children}) => { const logOutSession = setTimeout(() => { logout() }, Number(process.env.REACT_APP_LOGOUT_SESSION_TIMEOUT)) - // eslint-disable-next-line - + return (() => { clearInterval(logOutSession) }) + // eslint-disable-next-line }, [pathname]) return showSplashScreen ? : <>{children} -- 2.34.1