props/MultiShop/client/src/services/http.js

24 lines
630 B
JavaScript
Raw Normal View History

import axios from "axios";
let currentAuthorizationInterceptorID = null;
const http = axios.create({
baseURL: window.location.origin + "/api",
timeout: 2000,
});
function addBearerTokenInterceptor(token) {
currentAuthorizationInterceptorID = http.interceptors.request.use((config) => {
config.headers.Authorization = `Bearer ${token}`;
return config;
}, (err) => {
console.error(err);
});
}
function removeBearerTokenInterceptor() {
http.interceptors.request.eject(currentAuthorizationInterceptorID);
}
export { http, addBearerTokenInterceptor, removeBearerTokenInterceptor };