fetching
This commit is contained in:
@@ -91,10 +91,12 @@ export const fetchWithAuth = async (url, options = {}) => {
|
|||||||
let token = localStorage.getItem('access');
|
let token = localStorage.getItem('access');
|
||||||
|
|
||||||
// Configurar headers por defecto
|
// Configurar headers por defecto
|
||||||
const defaultHeaders = {
|
let defaultHeaders = {};
|
||||||
'Content-Type': 'application/json',
|
if (token) defaultHeaders['Authorization'] = `Bearer ${token}`;
|
||||||
...(token && { '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';
|
||||||
|
}
|
||||||
|
|
||||||
// Combinar headers
|
// Combinar headers
|
||||||
const finalOptions = {
|
const finalOptions = {
|
||||||
|
|||||||
Reference in New Issue
Block a user