92 lines
3.5 KiB
JavaScript
92 lines
3.5 KiB
JavaScript
import React from "react";
|
|
import Axios from "axios";
|
|
|
|
class usersService {
|
|
constructor() {
|
|
console.log("Er are here anyway");
|
|
}
|
|
|
|
logInUser(reqData) {
|
|
// debugger;
|
|
/*
|
|
clean up the request data here
|
|
*/
|
|
return this.postAuxEnd("/login", reqData);
|
|
}
|
|
|
|
//---------------------------------------- -----
|
|
//---------------------------------------- -----
|
|
// Unified call below
|
|
//---------------------------------------- -----
|
|
//---------------------------------------- -----
|
|
getAuxEnd(uri, reqData) {
|
|
const endPoint = process.env.REACT_APP_USERS_ENDPOINT + uri;
|
|
return Axios.get(endPoint)
|
|
.then((response) => {
|
|
// console.log(response);
|
|
// res = response;
|
|
// console.log("~~~~~~~ Toks2 GET ~~~~~~~~");
|
|
return response;
|
|
})
|
|
.catch((error) => {
|
|
if (error.response) {
|
|
//response status is an error code
|
|
console.log(error.response.status);
|
|
} else if (error.request) {
|
|
//response not received though the request was sent
|
|
console.log(error.request);
|
|
} else {
|
|
//an error occurred when setting up the request
|
|
console.log(error.message);
|
|
}
|
|
});
|
|
}
|
|
|
|
postAuxEnd(uri, reqData) {
|
|
const endPoint = process.env.REACT_APP_USERS_ENDPOINT + uri;
|
|
const token = '..your token..'
|
|
let axiosConfig = {
|
|
headers: {
|
|
'Accept': 'application/json',
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Content-Type': 'application/json;charset=UTF-8',
|
|
'Authorization': `Basic ${token}`,
|
|
}
|
|
};
|
|
//Access-Control-Allow-Origin
|
|
var postData = {
|
|
email: "test@test.com",
|
|
password: "password"
|
|
};
|
|
// Axios.defaults.headers.post['Content-Type'] ='application/json;charset=utf-8';
|
|
// Axios.defaults.headers.post['Access-Control-Allow-Origin'] = '*'; //,axiosConfig
|
|
return Axios.post(endPoint, postData)
|
|
.then((response) => {
|
|
console.log(response);
|
|
// res = response;
|
|
console.log("~~~~~~~ Toks2 POST ~~~~~~~~");
|
|
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.message);
|
|
console.log("ERROR3-------------------------------------------------------");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
export default usersService;
|