import axios from 'axios'; import { getApiBaseUrl } from './config'; const API_BASE_URL = getApiBaseUrl(); export const api = axios.create({ baseURL: API_BASE_URL, headers: { 'Content-Type': 'application/json', }, withCredentials: true, }); // Request interceptor for auth api.interceptors.request.use( (config) => { const token = localStorage.getItem('auth_token'); if (token) { config.headers.Authorization = `Bearer ${token}`; } return config; }, (error) => Promise.reject(error) ); // Response interceptor for error handling api.interceptors.response.use( (response) => response, (error) => { if (error.response?.status === 401) { localStorage.removeItem('auth_token'); window.location.href = '/login'; } return Promise.reject(error); } ); export default api;