import { UseQueryOptions, QueryObserverOptions, } from "@tanstack/react-query"; import axios from "axios"; // --------------------------------------------------------------------------- // Axios client // --------------------------------------------------------------------------- export const client = axios.create({ baseURL: import.meta.env.VITE_API_URL, }); // Attach auth token to every request client.interceptors.request.use((config) => { // TODO: replace with secure storage (cookie/localStorage/auth provider) const token = document.cookie .split("; ") .find((row) => row.startsWith("auth-token=")) ?.split("=")[1]; if (token) { config.headers.Authorization = `Bearer ${token}`; } return config; }); // Handle auth errors globally client.interceptors.response.use( (response) => response, (error) => { if (error.response?.status === 401) { window.location.href = "/auth"; } return Promise.reject(error); } );