Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c5163b80c7 | |||
| ab885a69d9 | |||
| 2cbeb66502 | |||
| 0001fe5d59 | |||
| 2ee928a2e3 |
@@ -17,3 +17,6 @@ REACT_APP_THEME_API_URL=https://preview.keenthemes.com/theme-api/api
|
|||||||
REACT_APP_TERMS_LINK='https://www.float.sg/terms'
|
REACT_APP_TERMS_LINK='https://www.float.sg/terms'
|
||||||
REACT_APP_CONTACT_LINK='https://www.float.sg/contact'
|
REACT_APP_CONTACT_LINK='https://www.float.sg/contact'
|
||||||
REACT_APP_ABOUT_LINK='https://www.float.sg/about'
|
REACT_APP_ABOUT_LINK='https://www.float.sg/about'
|
||||||
|
|
||||||
|
REACT_APP_LOGIN_ERROR_TIMEOUT=5000
|
||||||
|
REACT_APP_LOGOUT_SESSION_TIMEOUT=300000
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export function Login() {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const {saveAuth, setCurrentUser} = useAuth()
|
const {saveAuth, setCurrentUser} = useAuth()
|
||||||
|
const statusChecker = document.getElementById('formik-status')
|
||||||
|
|
||||||
const formik = useFormik({
|
const formik = useFormik({
|
||||||
initialValues,
|
initialValues,
|
||||||
@@ -48,14 +49,25 @@ export function Login() {
|
|||||||
saveAuth(auth)
|
saveAuth(auth)
|
||||||
// const {data: user} = await getUserByToken(auth.api_token)
|
// const {data: user} = await getUserByToken(auth.api_token)
|
||||||
// setCurrentUser(user)
|
// setCurrentUser(user)
|
||||||
|
if(auth.status <= 0){
|
||||||
|
setStatus(auth.error_msg)
|
||||||
|
setSubmitting(false)
|
||||||
|
setLoading(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
setCurrentUser(auth.profile)
|
setCurrentUser(auth.profile)
|
||||||
|
console.log(auth)
|
||||||
navigate('/dashboard')
|
navigate('/dashboard')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
saveAuth(undefined)
|
saveAuth(undefined)
|
||||||
setStatus('The login details are incorrect')
|
setStatus('An error occurred')
|
||||||
setSubmitting(false)
|
setSubmitting(false)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
} finally {
|
||||||
|
setTimeout(() => {
|
||||||
|
setStatus(null)
|
||||||
|
}, Number(process.env.REACT_APP_LOGIN_ERROR_TIMEOUT))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -126,7 +138,7 @@ export function Login() {
|
|||||||
{/* end::Separator */}
|
{/* end::Separator */}
|
||||||
|
|
||||||
{formik.status ? (
|
{formik.status ? (
|
||||||
<div className='mb-lg-15 alert alert-danger'>
|
<div id='formik-status' className='mb-lg-15 alert alert-danger'>
|
||||||
<div className='alert-text font-weight-bold'>{formik.status}</div>
|
<div className='alert-text font-weight-bold'>{formik.status}</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
@@ -163,7 +175,7 @@ export function Login() {
|
|||||||
<label className='form-label fw-bolder text-dark fs-6 mb-0'>Password</label>
|
<label className='form-label fw-bolder text-dark fs-6 mb-0'>Password</label>
|
||||||
<input
|
<input
|
||||||
type='password'
|
type='password'
|
||||||
placeHolder="●●●●●●"
|
placeholder="●●●●●●"
|
||||||
autoComplete='off'
|
autoComplete='off'
|
||||||
{...formik.getFieldProps('password')}
|
{...formik.getFieldProps('password')}
|
||||||
className={clsx(
|
className={clsx(
|
||||||
|
|||||||
@@ -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,6 +62,7 @@ const AuthProvider: FC<WithChildren> = ({children}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AuthInit: FC<WithChildren> = ({children}) => {
|
const AuthInit: FC<WithChildren> = ({children}) => {
|
||||||
|
const {pathname} = useLocation()
|
||||||
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)
|
||||||
@@ -95,8 +97,17 @@ const AuthInit: FC<WithChildren> = ({children}) => {
|
|||||||
logout()
|
logout()
|
||||||
setShowSplashScreen(false)
|
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
|
// eslint-disable-next-line
|
||||||
}, [])
|
}, [pathname])
|
||||||
|
|
||||||
return showSplashScreen ? <LayoutSplashScreen /> : <>{children}</>
|
return showSplashScreen ? <LayoutSplashScreen /> : <>{children}</>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user