diff --git a/.env b/.env index 8f80f26..cd11150 100644 --- a/.env +++ b/.env @@ -18,4 +18,5 @@ 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' -REACT_APP_LOGIN_ERROR_TIMEOUT=5000 \ No newline at end of file +REACT_APP_LOGIN_ERROR_TIMEOUT=5000 +REACT_APP_LOGOUT_SESSION_TIMEOUT=300000 diff --git a/src/app/modules/auth/core/Auth.tsx b/src/app/modules/auth/core/Auth.tsx index 930131c..4351b7f 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)) + + return (() => { + clearInterval(logOutSession) + }) // eslint-disable-next-line - }, []) + }, [pathname]) return showSplashScreen ? : <>{children} }