panjareh
Version:
Panjareh using aparat and phoenix-video-player to play videos on desktops and tvs.
34 lines (26 loc) • 763 B
JavaScript
import Axios from "axios";
import { AuthStorage } from "../../utils/authStorage";
import { catchAxiosError } from "./axios-error-handler";
const axios = Axios.create({
timeout: 10000,
headers: {
"Content-Type": "application/json",
},
responseType: "json",
});
const getData = (response) => response.data;
axios.interceptors.response.use(getData, catchAxiosError);
axios.interceptors.request.use((config) => {
const accessToken = AuthStorage.getToken();
if (accessToken) {
if (!config.headers["Authorization"]) {
config.headers["Authorization"] = `Bearer ${accessToken}`;
}
} else {
if (config.headers["Authorization"]) {
delete config.headers["Authorization"];
}
}
return config;
});
export default axios;