Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| accace3f60 |
@@ -18,3 +18,4 @@ 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_CONTACT_US=https://www.float.sg/contact
|
||||||
REACT_APP_SITE_TERMS=https://www.float.sg/terms
|
REACT_APP_SITE_TERMS=https://www.float.sg/terms
|
||||||
REACT_APP_SITE_ABOUT_US=https://www.float.sg/about
|
REACT_APP_SITE_ABOUT_US=https://www.float.sg/about
|
||||||
|
REACT_APP_SESSION_TIMEOUT=300000
|
||||||
@@ -22,19 +22,19 @@ const SidebarLogo = () => {
|
|||||||
{config.layoutType === 'dark-sidebar' ? (
|
{config.layoutType === 'dark-sidebar' ? (
|
||||||
<img
|
<img
|
||||||
alt='Logo'
|
alt='Logo'
|
||||||
src={toAbsoluteUrl('/media/logos/logo.png')}
|
src={toAbsoluteUrl('/media/logos/default-dark.svg')}
|
||||||
className='h-25px app-sidebar-logo-default'
|
className='h-25px app-sidebar-logo-default'
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<img
|
<img
|
||||||
alt='Logo'
|
alt='Logo'
|
||||||
src={toAbsoluteUrl('/media/logos/logo.png')}
|
src={toAbsoluteUrl('/media/logos/default.svg')}
|
||||||
className='h-25px app-sidebar-logo-default theme-light-show'
|
className='h-25px app-sidebar-logo-default theme-light-show'
|
||||||
/>
|
/>
|
||||||
<img
|
<img
|
||||||
alt='Logo'
|
alt='Logo'
|
||||||
src={toAbsoluteUrl('/media/logos/logo.png')}
|
src={toAbsoluteUrl('/media/logos/default-dark.svg')}
|
||||||
className='h-25px app-sidebar-logo-default theme-dark-show'
|
className='h-25px app-sidebar-logo-default theme-dark-show'
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
Dispatch,
|
Dispatch,
|
||||||
SetStateAction,
|
SetStateAction,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
|
import {useLocation} from 'react-router-dom'
|
||||||
import {LayoutSplashScreen} from '../../../../_res/layout/core'
|
import {LayoutSplashScreen} from '../../../../_res/layout/core'
|
||||||
import {AuthModel, UserModel} from './_models'
|
import {AuthModel, UserModel} from './_models'
|
||||||
import * as authHelper from './AuthHelpers'
|
import * as authHelper from './AuthHelpers'
|
||||||
@@ -61,11 +62,17 @@ const AuthProvider: FC<WithChildren> = ({children}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AuthInit: FC<WithChildren> = ({children}) => {
|
const AuthInit: FC<WithChildren> = ({children}) => {
|
||||||
|
const pathname = useLocation().pathname
|
||||||
const {auth, logout, setCurrentUser} = useAuth()
|
const {auth, logout, setCurrentUser} = useAuth()
|
||||||
const didRequest = useRef(false)
|
const didRequest = useRef(false)
|
||||||
const [showSplashScreen, setShowSplashScreen] = useState(true)
|
const [showSplashScreen, setShowSplashScreen] = useState(true)
|
||||||
// We should request user by authToken (IN OUR EXAMPLE IT'S API_TOKEN) before rendering the application
|
// We should request user by authToken (IN OUR EXAMPLE IT'S API_TOKEN) before rendering the application
|
||||||
useEffect(() => {
|
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) => {
|
const requestUser = async (apiToken: string) => {
|
||||||
try {
|
try {
|
||||||
if (!didRequest.current) {
|
if (!didRequest.current) {
|
||||||
@@ -96,7 +103,11 @@ const AuthInit: FC<WithChildren> = ({children}) => {
|
|||||||
setShowSplashScreen(false)
|
setShowSplashScreen(false)
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}, [])
|
|
||||||
|
return ()=>{ // clears session timeout side effect
|
||||||
|
clearInterval(logoutSession)
|
||||||
|
}
|
||||||
|
}, [pathname])
|
||||||
|
|
||||||
return showSplashScreen ? <LayoutSplashScreen /> : <>{children}</>
|
return showSplashScreen ? <LayoutSplashScreen /> : <>{children}</>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user