From accace3f602447d92beab1557ba47c8b3cf11ce7 Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Sat, 15 Apr 2023 16:06:57 +0100 Subject: [PATCH 1/2] added a function to expire session after 5 mins --- .env | 3 ++- src/app/modules/auth/core/Auth.tsx | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.env b/.env index ee32553..079db2f 100644 --- a/.env +++ b/.env @@ -17,4 +17,5 @@ REACT_APP_THEME_API_URL=https://preview.keenthemes.com/theme-api/api REACT_APP_SITE_CONTACT_US=https://www.float.sg/contact REACT_APP_SITE_TERMS=https://www.float.sg/terms -REACT_APP_SITE_ABOUT_US=https://www.float.sg/about \ No newline at end of file +REACT_APP_SITE_ABOUT_US=https://www.float.sg/about +REACT_APP_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 77a7ef2..33a2b03 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,11 +62,17 @@ const AuthProvider: FC = ({children}) => { } const AuthInit: FC = ({children}) => { + const pathname = useLocation().pathname const {auth, logout, setCurrentUser} = useAuth() const didRequest = useRef(false) const [showSplashScreen, setShowSplashScreen] = useState(true) // We should request user by authToken (IN OUR EXAMPLE IT'S API_TOKEN) before rendering the application useEffect(() => { + // function to expire session after 5 mins + let logoutSession = setTimeout(()=>{ //expire session after 5 mins + logout() + }, Number(process.env.REACT_APP_SESSION_TIMEOUT)) + const requestUser = async (apiToken: string) => { try { if (!didRequest.current) { @@ -96,7 +103,11 @@ const AuthInit: FC = ({children}) => { setShowSplashScreen(false) } // eslint-disable-next-line - }, []) + + return ()=>{ // clears session timeout side effect + clearInterval(logoutSession) + } + }, [pathname]) return showSplashScreen ? : <>{children} } -- 2.34.1 From f045ebcfe4752f1f2d3c742a855d5159e274db99 Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Mon, 17 Apr 2023 15:00:08 +0100 Subject: [PATCH 2/2] loggedin logo changed to float logo --- src/_metronic/layout/components/sidebar/SidebarLogo.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/_metronic/layout/components/sidebar/SidebarLogo.tsx b/src/_metronic/layout/components/sidebar/SidebarLogo.tsx index c4194fe..b608515 100644 --- a/src/_metronic/layout/components/sidebar/SidebarLogo.tsx +++ b/src/_metronic/layout/components/sidebar/SidebarLogo.tsx @@ -22,19 +22,19 @@ const SidebarLogo = () => { {config.layoutType === 'dark-sidebar' ? ( Logo ) : ( <> Logo Logo -- 2.34.1