42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import dataProvider from "@refinedev/simple-rest";
|
|
|
|
import { TOKEN_KEY } from "@providers";
|
|
|
|
import axios from "axios";
|
|
import { languageStore } from "@stores";
|
|
|
|
export const axiosInstance = axios.create({
|
|
baseURL: import.meta.env.VITE_KRBL_API,
|
|
});
|
|
|
|
axiosInstance.interceptors.request.use((config) => {
|
|
// Добавляем токен авторизации
|
|
const token = localStorage.getItem(TOKEN_KEY);
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`;
|
|
}
|
|
|
|
// Добавляем язык в кастомный заголовок
|
|
|
|
config.headers["X-Language"] = config.headers["Accept-Language"];
|
|
|
|
return config;
|
|
});
|
|
|
|
export const axiosInstanceForGet = axios.create({
|
|
baseURL: import.meta.env.VITE_KRBL_API,
|
|
});
|
|
|
|
axiosInstanceForGet.interceptors.request.use((config) => {
|
|
const token = localStorage.getItem(TOKEN_KEY);
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`;
|
|
}
|
|
|
|
config.headers["X-Language"] = languageStore.language;
|
|
return config;
|
|
});
|
|
const apiUrl = import.meta.env.VITE_KRBL_API;
|
|
|
|
export const customDataProvider = dataProvider(apiUrl, axiosInstance);
|