Harrison Deng
57f67391f1
After reconsidering where I want to take this project, I realized that a MPA is more fitting.
24 lines
642 B
JavaScript
24 lines
642 B
JavaScript
import axios from "axios";
|
|
|
|
let currentAuthorizationInterceptorID = null;
|
|
|
|
const apiHttp = axios.create({
|
|
baseURL: window.location.origin + "/api",
|
|
timeout: 3000,
|
|
});
|
|
|
|
function addBearerTokenInterceptor(token) {
|
|
currentAuthorizationInterceptorID = apiHttp.interceptors.request.use((config) => {
|
|
config.headers.Authorization = `Bearer ${token}`;
|
|
return config;
|
|
}, (err) => {
|
|
console.error(err);
|
|
});
|
|
}
|
|
|
|
function removeBearerTokenInterceptor() {
|
|
apiHttp.interceptors.request.eject(currentAuthorizationInterceptorID);
|
|
}
|
|
|
|
export { apiHttp, addBearerTokenInterceptor, removeBearerTokenInterceptor };
|