added axios verb call function file #5

Merged
ameye merged 1 commits from axios-call-helper into master 2024-05-01 14:00:50 +00:00
2 changed files with 65 additions and 5 deletions
@@ -0,0 +1,50 @@
import axios from "axios";
export function postAuxEnd(uri:string, reqData:any):Promise<any> {
// const endPoint = process.env.REACT_APP_USERS_ENDPOINT + uri;
const formData = new FormData();
for (let value in reqData) {
formData.append(value, reqData[value]);
}
return axios.post(uri, reqData)
.then((response) => {
console.log(response);
// if (response.data.internal_return == "-9999") {
// localStorage.clear();
// window.location.href = `/login?sessionExpired=true`;
// }
return response;
})
.catch((error) => {
if (error.response) {
//response status is an error code
console.log(
"ERROR-------------------------------------------------------"
);
console.log(error.response.status);
console.log(
"ERROR-------------------------------------------------------"
);
} else if (error.request) {
//response not received though the request was sent
console.log(
"ERROR2-------------------------------------------------------"
);
console.log(error?.request);
console.log(
"ERROR2-------------------------------------------------------"
);
} else {
//an error occurred when setting up the request
console.log(
"ERROR3-------------------------------------------------------"
);
console.log(error);
console.log(
"ERROR3-------------------------------------------------------"
);
}
});
}
+15 -5
View File
@@ -1,19 +1,29 @@
import axios from "axios";
import { AuthModel, UserModel } from "./_models";
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 REGISTER_URL = `${API_URL}/register`;
export const REQUEST_PASSWORD_URL = `${API_URL}/forgot_password`;
// Server should return AuthModel
//Function to login user in // Server should return AuthModel
export function login(email: string, password: string) {
return axios.post<AuthModel>(LOGIN_URL, {
email,
password,
});
// return axios.post<AuthModel>(LOGIN_URL, {
// email,
// password,
// });
// let formData = new FormData()
// formData.append('username', email)
// formData.append('pass', password)
// return axios.post<AuthModel>(LOGIN_URL, formData);
return postAuxEnd(LOGIN_URL, {email, password})
}
// Server should return AuthModel