IO-256 Authorization and Basic Calls

This commit is contained in:
Patrick Fic
2021-08-27 15:42:32 -07:00
parent 724c097d52
commit 5284ee2ef9
13 changed files with 6559 additions and 126 deletions

View File

@@ -1,9 +1,6 @@
import axios from "axios";
import { auth } from "../firebase/firebase.utils";
import { Cookies } from "react-cookie";
const cookies = new Cookies();
if (process.env.NODE_ENV === "production") {
axios.defaults.baseURL =
process.env.REACT_APP_AXIOS_BASE_API_URL || "https://api.imex.online/";
@@ -18,38 +15,6 @@ export const axiosAuthInterceptorId = axios.interceptors.request.use(
}
}
//Check if Qbo Cookies need to be refreshed.
const qbo_access_token = cookies.get("qbo_access_token");
const qbo_refresh_token = cookies.get("qbo_refresh_token");
if (!qbo_refresh_token) {
//Kill both values just in case.
cookies.remove("qbo_access_token");
cookies.remove("qbo_refresh_token");
return config;
}
//Are they expired?
if (!qbo_access_token) {
//Refresh it first.
const response = await axios.get(`/qbo/refresh`, {
withCredentials: true,
});
let expires = new Date();
expires.setTime(expires.getTime() + response.data.expires_in * 1000);
cookies.set("qbo_access_token", response.data.access_token, {
path: "/",
expires,
});
expires = new Date();
expires.setTime(
expires.getTime() + response.data.x_refresh_token_expires_in * 1000
);
cookies.set("qbo_refresh_token", response.data.refresh_token, {
path: "/",
expires,
});
}
return config;
},
(error) => Promise.reject(error)