Semodifico fetch with auth

This commit is contained in:
2025-08-15 13:40:49 -06:00
parent e86547d10d
commit 80acbeb023
2 changed files with 6 additions and 8 deletions

View File

@@ -91,12 +91,10 @@ export const fetchWithAuth = async (url, options = {}) => {
let token = localStorage.getItem('access');
// Configurar headers por defecto
let defaultHeaders = {};
if (token) defaultHeaders['Authorization'] = `Bearer ${token}`;
// Solo poner Content-Type si no es GET o si hay body
if ((options.method && options.method.toUpperCase() !== 'GET') || options.body) {
defaultHeaders['Content-Type'] = 'application/json';
}
const defaultHeaders = {
'Content-Type': 'application/json',
...(token && { 'Authorization': `Bearer ${token}` })
};
// Combinar headers
const finalOptions = {