From f7f728c06621514cd200a2146f89e082a4c65ff0 Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Thu, 2 May 2024 14:00:57 +0100 Subject: [PATCH] added new login API --- .../users-list/core/_requests.ts | 4 +-- .../users-list/table/UsersTable.tsx | 2 +- src/app/modules/auth/core/AuthHelpers.ts | 6 ++--- src/app/modules/auth/core/AxiosCallHelper.ts | 4 +-- src/app/modules/auth/core/_models.ts | 21 +++++++++++++++ src/app/modules/auth/core/_requests.ts | 26 +++++++++---------- 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/app/modules/apps/user-management/users-list/core/_requests.ts b/src/app/modules/apps/user-management/users-list/core/_requests.ts index 1eeed2f..a585521 100644 --- a/src/app/modules/apps/user-management/users-list/core/_requests.ts +++ b/src/app/modules/apps/user-management/users-list/core/_requests.ts @@ -13,9 +13,9 @@ const NEW_USER_ENDPOINT = import.meta.env.VITE_APP_USER_ENDPOINT // .get(`${GET_USERS_URL}?${query}`) // .then((d: AxiosResponse) => d.data); // }; -const getStartedUsers = (query: string): Promise => { +const getStartedUsers = (query: string): Promise => { // FUNCTION TO GET USERS THAT HAVE STARTED LOAN APPLICATION return axios - .get(`${NEW_USER_ENDPOINT}/loan/started?${query}`) + .get(`${NEW_USER_ENDPOINT}/loan/started`) .then((d: AxiosResponse) => d.data); }; diff --git a/src/app/modules/apps/user-management/users-list/table/UsersTable.tsx b/src/app/modules/apps/user-management/users-list/table/UsersTable.tsx index f48b4b4..5898f4c 100644 --- a/src/app/modules/apps/user-management/users-list/table/UsersTable.tsx +++ b/src/app/modules/apps/user-management/users-list/table/UsersTable.tsx @@ -11,7 +11,7 @@ import {KTCardBody} from '../../../../../../_digifi/helpers' const UsersTable = () => { const users = useQueryResponseData() - // console.log('users', users) + console.log('users', users) const isLoading = useQueryResponseLoading() const data = useMemo(() => users, [users]) const columns = useMemo(() => usersColumns, []) diff --git a/src/app/modules/auth/core/AuthHelpers.ts b/src/app/modules/auth/core/AuthHelpers.ts index 06e0e53..59d02af 100644 --- a/src/app/modules/auth/core/AuthHelpers.ts +++ b/src/app/modules/auth/core/AuthHelpers.ts @@ -53,9 +53,9 @@ 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.api_token) { + // config.headers.Authorization = `Bearer ${auth.api_token}` + // } return config }, diff --git a/src/app/modules/auth/core/AxiosCallHelper.ts b/src/app/modules/auth/core/AxiosCallHelper.ts index 5ecdbd6..b25e2cf 100644 --- a/src/app/modules/auth/core/AxiosCallHelper.ts +++ b/src/app/modules/auth/core/AxiosCallHelper.ts @@ -1,12 +1,12 @@ import axios from "axios"; export function postAuxEnd(uri:string, reqData:any):Promise { - // const endPoint = process.env.REACT_APP_USERS_ENDPOINT + uri; + const endPoint = import.meta.env.VITE_APP_USER_ENDPOINT + uri; const formData = new FormData(); for (let value in reqData) { formData.append(value, reqData[value]); } - return axios.post(uri, reqData) + return axios.post(endPoint, formData) .then((response) => { console.log(response); // if (response.data.internal_return == "-9999") { diff --git a/src/app/modules/auth/core/_models.ts b/src/app/modules/auth/core/_models.ts index 81576cc..d9765cd 100644 --- a/src/app/modules/auth/core/_models.ts +++ b/src/app/modules/auth/core/_models.ts @@ -1,6 +1,18 @@ export interface AuthModel { api_token: string refreshToken?: string + + message?: string + call_return?: string + username: string + token?: string + id?: string + first_name?: string + last_name?: string + email?: string + email_verified_at?: string + created_at?: string + updated_at?: string } export interface UserAddressModel { @@ -64,4 +76,13 @@ export interface UserModel { communication?: UserCommunicationModel address?: UserAddressModel socialNetworks?: UserSocialNetworksModel + + api_token: string + refreshToken?: string + message?: string + call_return?: string + token?: string + email_verified_at?: string + created_at?: string + updated_at?: string } diff --git a/src/app/modules/auth/core/_requests.ts b/src/app/modules/auth/core/_requests.ts index a64e73d..724b653 100644 --- a/src/app/modules/auth/core/_requests.ts +++ b/src/app/modules/auth/core/_requests.ts @@ -5,9 +5,11 @@ import { postAuxEnd } from "./AxiosCallHelper"; const API_URL = import.meta.env.VITE_APP_API_URL; -export const GET_USER_BY_ACCESSTOKEN_URL = `${API_URL}/verify_token`; -export const LOGIN_URL = `${API_URL}/login`; -// export const LOGIN_URL = 'https://digifi-apidev.chiefsoft.net/digibko/v1/identity/token' +// export const GET_USER_BY_ACCESSTOKEN_URL = `${API_URL}/verify_token`; +// export const LOGIN_URL = `${API_URL}/login`; + +export const GET_USER_BY_ACCESSTOKEN_URL = '/identity/verify_token' +export const LOGIN_URL = '/identity/token' export const REGISTER_URL = `${API_URL}/register`; export const REQUEST_PASSWORD_URL = `${API_URL}/forgot_password`; @@ -17,13 +19,7 @@ export function login(email: string, password: string) { // email, // password, // }); - - // let formData = new FormData() - // formData.append('username', email) - // formData.append('pass', password) - // return axios.post(LOGIN_URL, formData); - - return postAuxEnd(LOGIN_URL, {email, password}) + return postAuxEnd(LOGIN_URL, {username:email, pass:password}) } // Server should return AuthModel @@ -50,8 +46,12 @@ export function requestPassword(email: string) { }); } +// export function getUserByToken(token: string) { +// return axios.post(GET_USER_BY_ACCESSTOKEN_URL, { +// api_token: token, +// }); +// } + export function getUserByToken(token: string) { - return axios.post(GET_USER_BY_ACCESSTOKEN_URL, { - api_token: token, - }); + return postAuxEnd(GET_USER_BY_ACCESSTOKEN_URL, {token}) } -- 2.34.1