Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0001fe5d59 | |||
| 2ee928a2e3 | |||
| dd581a8cdc | |||
| 350626cfc3 | |||
| 8b8a1548e1 | |||
| b26dd7d574 | |||
| 3ef37b0b9e | |||
| d3d08f9892 | |||
| 618fbaf72e | |||
| 8d0c252900 | |||
| 37ef15c591 |
@@ -2,7 +2,7 @@ PUBLIC_URL=http://localhost:3000/
|
|||||||
PORT=3000
|
PORT=3000
|
||||||
PRIMARY_APP_API_URL=https://preview.keenthemes.com/metronic8/laravel/api
|
PRIMARY_APP_API_URL=https://preview.keenthemes.com/metronic8/laravel/api
|
||||||
REACT_APP_BASE_LAYOUT_CONFIG_KEY='metronic-react-demo1-8150'
|
REACT_APP_BASE_LAYOUT_CONFIG_KEY='metronic-react-demo1-8150'
|
||||||
REACT_APP_API_URL=https://preview.keenthemes.com/metronic8/laravel/api
|
REACT_APP_API_URL=https://float-gat.dev.chiefsoft.net/en/fleetweb/api/v1/
|
||||||
REACT_APP_VERSION=v8.1.5
|
REACT_APP_VERSION=v8.1.5
|
||||||
REACT_APP_THEME_NAME=WrenchBoard
|
REACT_APP_THEME_NAME=WrenchBoard
|
||||||
REACT_APP_THEME_DEMO=dashboard
|
REACT_APP_THEME_DEMO=dashboard
|
||||||
@@ -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_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_LOGOUT_SESSION_TIMEOUT=300000
|
||||||
@@ -8,6 +8,7 @@ import {getUserByToken, login} from '../core/_requests'
|
|||||||
import {toAbsoluteUrl} from '../../../../_metronic/helpers'
|
import {toAbsoluteUrl} from '../../../../_metronic/helpers'
|
||||||
import {useAuth} from '../core/Auth'
|
import {useAuth} from '../core/Auth'
|
||||||
// import Logo from '../../../../../public/media/logos/favicon.ico'
|
// import Logo from '../../../../../public/media/logos/favicon.ico'
|
||||||
|
import {useNavigate} from 'react-router-dom'
|
||||||
|
|
||||||
const loginSchema = Yup.object().shape({
|
const loginSchema = Yup.object().shape({
|
||||||
email: Yup.string()
|
email: Yup.string()
|
||||||
@@ -22,8 +23,8 @@ const loginSchema = Yup.object().shape({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
email: 'johndoe@email.com',
|
email: '',
|
||||||
password: '****',
|
password: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -33,6 +34,7 @@ const initialValues = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function Login() {
|
export function Login() {
|
||||||
|
const navigate = useNavigate()
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const {saveAuth, setCurrentUser} = useAuth()
|
const {saveAuth, setCurrentUser} = useAuth()
|
||||||
|
|
||||||
@@ -44,8 +46,10 @@ export function Login() {
|
|||||||
try {
|
try {
|
||||||
const {data: auth} = await login(values.email, values.password)
|
const {data: auth} = await login(values.email, values.password)
|
||||||
saveAuth(auth)
|
saveAuth(auth)
|
||||||
const {data: user} = await getUserByToken(auth.api_token)
|
// const {data: user} = await getUserByToken(auth.api_token)
|
||||||
setCurrentUser(user)
|
// setCurrentUser(user)
|
||||||
|
setCurrentUser(auth.profile)
|
||||||
|
navigate('/dashboard')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
saveAuth(undefined)
|
saveAuth(undefined)
|
||||||
@@ -121,11 +125,19 @@ export function Login() {
|
|||||||
</div>
|
</div>
|
||||||
{/* end::Separator */}
|
{/* end::Separator */}
|
||||||
|
|
||||||
|
{formik.status ? (
|
||||||
|
<div className='mb-lg-15 alert alert-danger'>
|
||||||
|
<div className='alert-text font-weight-bold'>{formik.status}</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
null
|
||||||
|
)}
|
||||||
|
|
||||||
{/* begin::Form group */}
|
{/* begin::Form group */}
|
||||||
<div className='fv-row mb-8'>
|
<div className='fv-row mb-8'>
|
||||||
<label className='form-label fs-6 fw-bolder text-dark'>Email</label>
|
<label className='form-label fs-6 fw-bolder text-dark'>Email</label>
|
||||||
<input
|
<input
|
||||||
placeholder='Email'
|
placeholder='floatuser@email.com'
|
||||||
{...formik.getFieldProps('email')}
|
{...formik.getFieldProps('email')}
|
||||||
className={clsx(
|
className={clsx(
|
||||||
'form-control bg-transparent',
|
'form-control bg-transparent',
|
||||||
@@ -151,6 +163,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="●●●●●●"
|
||||||
autoComplete='off'
|
autoComplete='off'
|
||||||
{...formik.getFieldProps('password')}
|
{...formik.getFieldProps('password')}
|
||||||
className={clsx(
|
className={clsx(
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ export function Registration() {
|
|||||||
<span>
|
<span>
|
||||||
I Accept the{' '}
|
I Accept the{' '}
|
||||||
<a
|
<a
|
||||||
href='https://keenthemes.com/metronic/?page=faq'
|
href='#'
|
||||||
target='_blank'
|
target='_blank'
|
||||||
className='ms-1 link-primary'
|
className='ms-1 link-primary'
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -69,9 +71,12 @@ const AuthInit: FC<WithChildren> = ({children}) => {
|
|||||||
const requestUser = async (apiToken: string) => {
|
const requestUser = async (apiToken: string) => {
|
||||||
try {
|
try {
|
||||||
if (!didRequest.current) {
|
if (!didRequest.current) {
|
||||||
const {data} = await getUserByToken(apiToken)
|
// const {data} = await getUserByToken(apiToken)
|
||||||
if (data) {
|
// if (data) {
|
||||||
setCurrentUser(data)
|
// setCurrentUser(data)
|
||||||
|
// }
|
||||||
|
if(localStorage.getItem('kt-auth-react-v')){
|
||||||
|
setCurrentUser(auth?.profile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -86,14 +91,23 @@ const AuthInit: FC<WithChildren> = ({children}) => {
|
|||||||
return () => (didRequest.current = true)
|
return () => (didRequest.current = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auth && auth.api_token) {
|
if (auth && auth.session_token) {
|
||||||
requestUser(auth.api_token)
|
requestUser(auth.session_token)
|
||||||
} else {
|
} else {
|
||||||
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}</>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ export function setupAxios(axios: any) {
|
|||||||
axios.interceptors.request.use(
|
axios.interceptors.request.use(
|
||||||
(config: {headers: {Authorization: string}}) => {
|
(config: {headers: {Authorization: string}}) => {
|
||||||
const auth = getAuth()
|
const auth = getAuth()
|
||||||
if (auth && auth.api_token) {
|
if (auth && auth.session_token) {
|
||||||
config.headers.Authorization = `Bearer ${auth.api_token}`
|
config.headers.Authorization = `Bearer ${auth.session_token}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export interface AuthModel {
|
export interface AuthModel {
|
||||||
api_token: string
|
session_token: string
|
||||||
refreshToken?: string
|
refreshToken?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ export const REQUEST_PASSWORD_URL = `${API_URL}/forgot_password`
|
|||||||
// Server should return AuthModel
|
// Server should return AuthModel
|
||||||
export function login(email: string, password: string) {
|
export function login(email: string, password: string) {
|
||||||
return axios.post<AuthModel>(LOGIN_URL, {
|
return axios.post<AuthModel>(LOGIN_URL, {
|
||||||
email,
|
username: email,
|
||||||
password,
|
password: password,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ export function requestPassword(email: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getUserByToken(token: string) {
|
export function getUserByToken(token: string) {
|
||||||
return axios.post<UserModel>(GET_USER_BY_ACCESSTOKEN_URL, {
|
return axios.get<UserModel>(GET_USER_BY_ACCESSTOKEN_URL, {
|
||||||
api_token: token,
|
session_token: token,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user