FIX: Allow axios to auto-detect Content-Type for FormData uploads
This commit is contained in:
parent
5d8da1ed29
commit
34f00d9f00
1 changed files with 6 additions and 5 deletions
|
|
@ -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;
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue