- Removed infinite query options and related functions from Trading212, User Registration, and User API files. - Updated API client base URLs in privateClient.ts and publicClient.ts to use environment variable for backend URL. - Refactored Downloader component to directly call API functions for video info retrieval instead of using a hook.
38 lines
890 B
TypeScript
38 lines
890 B
TypeScript
import axios, { type AxiosRequestConfig } from "axios";
|
|
|
|
const backendUrl = import.meta.env.VITE_BACKEND_URL || "http://localhost:8000";
|
|
|
|
|
|
// použij tohle pro API vyžadující autentizaci
|
|
export const privateApi = axios.create({
|
|
baseURL: backendUrl,
|
|
withCredentials: true, // potřebuje HttpOnly cookies
|
|
});
|
|
|
|
privateApi.interceptors.response.use(
|
|
(res) => res,
|
|
async (error) => {
|
|
const original = error.config;
|
|
|
|
if (error.response?.status === 401 && !original._retry) {
|
|
original._retry = true;
|
|
|
|
try {
|
|
await privateApi.post("/auth/refresh/");
|
|
return privateApi(original);
|
|
} catch {
|
|
// optional: logout
|
|
}
|
|
}
|
|
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
|
|
export const privateMutator = async <T>(
|
|
config: AxiosRequestConfig
|
|
): Promise<T> => {
|
|
const response = await privateApi.request<T>(config);
|
|
return response.data;
|
|
}; |