props/MultiShop/client/src/services/http.js
Harrison Deng 3d3c43b944 Began transition to Vue3.
Implemented logging in and logging out.

Implemented authenticated http client.

Laid some groundwork for SCSS.
2021-07-10 12:29:34 -05:00

24 lines
630 B
JavaScript

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 };