32 lines
666 B
TypeScript
32 lines
666 B
TypeScript
import axios from "axios";
|
|
// import { useHistory } from "react-router-dom";
|
|
const http = axios.create({
|
|
baseURL: process.env.REACT_APP_BACKEND_URL,
|
|
});
|
|
http.interceptors.request.use((config) => {
|
|
const authToken = localStorage.getItem("authToken");
|
|
if (authToken) {
|
|
config.headers.Authorization = `Bearer ${authToken}`;
|
|
}
|
|
|
|
return config;
|
|
});
|
|
http.interceptors.response.use(
|
|
(response) => response,
|
|
(error) => {
|
|
|
|
if (error.response && error.response.status === 401) {
|
|
|
|
|
|
|
|
// window.location.href = "/login";
|
|
|
|
// const history = useHistory();
|
|
// history.push("/login");
|
|
}
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
export default http;
|