Harrison Deng
3d3c43b944
Implemented logging in and logging out. Implemented authenticated http client. Laid some groundwork for SCSS.
24 lines
630 B
JavaScript
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 };
|