FIX: Allow axios to auto-detect Content-Type for FormData uploads

This commit is contained in:
DJP 2025-12-10 23:16:32 -05:00
parent 5d8da1ed29
commit 34f00d9f00

View file

@ -2,15 +2,16 @@ import axios from 'axios';
const api = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL || '/api/v1',
headers: {
'Content-Type': 'application/json',
},
withCredentials: true, // Send cookies with requests
});
// Request interceptor - cookies are sent automatically with withCredentials
// Request interceptor - set Content-Type based on data type
api.interceptors.request.use((config) => {
// Token is sent via cookie, no need to add Authorization header
// Let axios auto-detect Content-Type for FormData
// Only set application/json for non-FormData requests
if (!(config.data instanceof FormData)) {
config.headers['Content-Type'] = 'application/json';
}
return config;
});