import axios from 'axios'; const API_BASE_URL = import.meta.env.PUBLIC_API_URL || 'http://localhost:8080'; export const apiClient = axios.create({ baseURL: API_BASE_URL, withCredentials: true, // Important for session cookies headers: { 'Content-Type': 'application/json', }, }); // Response interceptor for error handling apiClient.interceptors.response.use( (response) => response, (error) => { if (error.response?.status === 401) { // Redirect to login on unauthorized if (typeof window !== 'undefined' && !window.location.pathname.includes('/')) { window.location.href = '/'; } } return Promise.reject(error); } );