feature/rbac y perfiles implementados

This commit is contained in:
2026-05-21 08:00:43 -06:00
parent 546a411df8
commit dc5f9fd6ce
29 changed files with 2007 additions and 977 deletions

View File

@@ -1,4 +1,5 @@
import { refreshToken } from './auth';
import { extractApiError } from './apiError';
const API_URL = import.meta.env.VITE_EFC_API_URL;
@@ -9,14 +10,13 @@ export async function fetchOrganizationUsage(token) {
'Content-Type': 'application/json',
},
});
if (res.status === 401) {
// Intentar refrescar el token
const refresh = localStorage.getItem('refresh');
if (refresh) {
try {
const data = await refreshToken(refresh);
localStorage.setItem('access', data.access);
// Reintenta la petición con el nuevo access token
res = await fetch(`${API_URL}/organization/uso-almacenamiento/mi_organizacion/`, {
headers: {
'Authorization': `Bearer ${data.access}`,
@@ -24,13 +24,14 @@ export async function fetchOrganizationUsage(token) {
},
});
if (res.status === 401) throw new Error('SESSION_EXPIRED');
} catch (err) {
} catch {
throw new Error('SESSION_EXPIRED');
}
} else {
throw new Error('SESSION_EXPIRED');
}
}
if (!res.ok) throw new Error('No autorizado o error en la petición');
if (!res.ok) throw new Error(await extractApiError(res));
return res.json();
}