From 618fbaf72e3c73045bcf584a0ad35010a2d7adb9 Mon Sep 17 00:00:00 2001 From: Ebube Date: Fri, 14 Apr 2023 06:11:16 +0100 Subject: [PATCH 1/3] initial commit --- .env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env b/.env index 69244f5..9cf80df 100644 --- a/.env +++ b/.env @@ -2,7 +2,7 @@ PUBLIC_URL=http://localhost:3000/ PORT=3000 PRIMARY_APP_API_URL=https://preview.keenthemes.com/metronic8/laravel/api 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_THEME_NAME=WrenchBoard REACT_APP_THEME_DEMO=dashboard -- 2.34.1 From d3d08f9892475f3fca32d53296642914b11615b1 Mon Sep 17 00:00:00 2001 From: ebube ojinta Date: Fri, 14 Apr 2023 13:52:47 -0700 Subject: [PATCH 2/3] fleet login implementation --- src/app/modules/auth/components/Login.tsx | 8 ++++++-- src/app/modules/auth/core/Auth.tsx | 6 +++--- src/app/modules/auth/core/AuthHelpers.ts | 4 ++-- src/app/modules/auth/core/_models.ts | 2 +- src/app/modules/auth/core/_requests.ts | 8 ++++---- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/app/modules/auth/components/Login.tsx b/src/app/modules/auth/components/Login.tsx index a4b8b56..8716df2 100644 --- a/src/app/modules/auth/components/Login.tsx +++ b/src/app/modules/auth/components/Login.tsx @@ -8,6 +8,7 @@ import {getUserByToken, login} from '../core/_requests' import {toAbsoluteUrl} from '../../../../_metronic/helpers' import {useAuth} from '../core/Auth' // import Logo from '../../../../../public/media/logos/favicon.ico' +import {useNavigate} from 'react-router-dom' const loginSchema = Yup.object().shape({ email: Yup.string() @@ -33,6 +34,7 @@ const initialValues = { */ export function Login() { + const navigate = useNavigate() const [loading, setLoading] = useState(false) const {saveAuth, setCurrentUser} = useAuth() @@ -44,8 +46,10 @@ export function Login() { try { const {data: auth} = await login(values.email, values.password) saveAuth(auth) - const {data: user} = await getUserByToken(auth.api_token) - setCurrentUser(user) + // const {data: user} = await getUserByToken(auth.api_token) + // setCurrentUser(user) + setCurrentUser(auth.profile) + navigate('/dashboard') } catch (error) { console.error(error) saveAuth(undefined) diff --git a/src/app/modules/auth/core/Auth.tsx b/src/app/modules/auth/core/Auth.tsx index b72f3c0..1c2f052 100644 --- a/src/app/modules/auth/core/Auth.tsx +++ b/src/app/modules/auth/core/Auth.tsx @@ -77,7 +77,7 @@ const AuthInit: FC = ({children}) => { } catch (error) { console.error(error) if (!didRequest.current) { - logout() + // logout() } } finally { setShowSplashScreen(false) @@ -86,8 +86,8 @@ const AuthInit: FC = ({children}) => { return () => (didRequest.current = true) } - if (auth && auth.api_token) { - requestUser(auth.api_token) + if (auth && auth.session_token) { + requestUser(auth.session_token) } else { logout() setShowSplashScreen(false) diff --git a/src/app/modules/auth/core/AuthHelpers.ts b/src/app/modules/auth/core/AuthHelpers.ts index f2e96da..c2559c0 100644 --- a/src/app/modules/auth/core/AuthHelpers.ts +++ b/src/app/modules/auth/core/AuthHelpers.ts @@ -52,8 +52,8 @@ export function setupAxios(axios: any) { axios.interceptors.request.use( (config: {headers: {Authorization: string}}) => { const auth = getAuth() - if (auth && auth.api_token) { - config.headers.Authorization = `Bearer ${auth.api_token}` + if (auth && auth.session_token) { + config.headers.Authorization = `Bearer ${auth.session_token}` } return config diff --git a/src/app/modules/auth/core/_models.ts b/src/app/modules/auth/core/_models.ts index 81576cc..b1815c2 100644 --- a/src/app/modules/auth/core/_models.ts +++ b/src/app/modules/auth/core/_models.ts @@ -1,5 +1,5 @@ export interface AuthModel { - api_token: string + session_token: string refreshToken?: string } diff --git a/src/app/modules/auth/core/_requests.ts b/src/app/modules/auth/core/_requests.ts index aaef532..8e72581 100644 --- a/src/app/modules/auth/core/_requests.ts +++ b/src/app/modules/auth/core/_requests.ts @@ -11,8 +11,8 @@ export const REQUEST_PASSWORD_URL = `${API_URL}/forgot_password` // Server should return AuthModel export function login(email: string, password: string) { return axios.post(LOGIN_URL, { - email, - password, + username: email, + password: password, }) } @@ -41,7 +41,7 @@ export function requestPassword(email: string) { } export function getUserByToken(token: string) { - return axios.post(GET_USER_BY_ACCESSTOKEN_URL, { - api_token: token, + return axios.get(GET_USER_BY_ACCESSTOKEN_URL, { + session_token: token, }) } -- 2.34.1 From 3ef37b0b9e943b982bafec579a4ae5181724eaa1 Mon Sep 17 00:00:00 2001 From: ebube ojinta Date: Fri, 14 Apr 2023 14:12:29 -0700 Subject: [PATCH 3/3] login --- src/app/modules/auth/core/Auth.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app/modules/auth/core/Auth.tsx b/src/app/modules/auth/core/Auth.tsx index 1c2f052..930131c 100644 --- a/src/app/modules/auth/core/Auth.tsx +++ b/src/app/modules/auth/core/Auth.tsx @@ -69,15 +69,18 @@ const AuthInit: FC = ({children}) => { const requestUser = async (apiToken: string) => { try { if (!didRequest.current) { - const {data} = await getUserByToken(apiToken) - if (data) { - setCurrentUser(data) + // const {data} = await getUserByToken(apiToken) + // if (data) { + // setCurrentUser(data) + // } + if(localStorage.getItem('kt-auth-react-v')){ + setCurrentUser(auth?.profile) } } } catch (error) { console.error(error) if (!didRequest.current) { - // logout() + logout() } } finally { setShowSplashScreen(false) -- 2.34.1