feat: version 3.0.0 -- Correcciones de auditoria de seguridad, accesibilidad y redundancia
Permisos (superadmin, viewer, busqueda, tareas recurrentes), bootstrap atomico, revocacion de JWT por version de sesion (028), control optimista de edicion (029), logo sin SVG + CSP, ingesta endurecida, correos escapados, borradores, paginacion de proyectos, accesibilidad de dialogos/controles e i18n. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { isTokenExpired } from '../utils/jwt.js';
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL || '/api';
|
||||
|
||||
let onUnauthorized = () => {};
|
||||
@@ -12,6 +14,11 @@ function getToken() {
|
||||
async function request(method, path, { body, isForm, extraHeaders } = {}) {
|
||||
const headers = { ...extraHeaders };
|
||||
const token = getToken();
|
||||
// Nunca operar con un token vencido: se corta la sesion aqui mismo, sin enviar la peticion.
|
||||
if (token && isTokenExpired(token)) {
|
||||
onUnauthorized({ expired: true });
|
||||
throw new Error('Sesion vencida');
|
||||
}
|
||||
if (token) headers.Authorization = `Bearer ${token}`;
|
||||
if (!isForm && body !== undefined) headers['Content-Type'] = 'application/json';
|
||||
|
||||
@@ -25,8 +32,8 @@ async function request(method, path, { body, isForm, extraHeaders } = {}) {
|
||||
const refreshedVaultToken = res.headers.get('x-vault-token');
|
||||
if (refreshedVaultToken) sessionStorage.setItem('plc_vault_token', refreshedVaultToken);
|
||||
|
||||
if (res.status === 401) {
|
||||
onUnauthorized();
|
||||
if (res.status === 401 && token) {
|
||||
onUnauthorized({ expired: true });
|
||||
}
|
||||
|
||||
if (res.status === 204) return null;
|
||||
@@ -36,7 +43,9 @@ async function request(method, path, { body, isForm, extraHeaders } = {}) {
|
||||
|
||||
if (!res.ok) {
|
||||
const message = payload?.error || `Error ${res.status}`;
|
||||
throw new Error(message);
|
||||
const error = new Error(message);
|
||||
error.status = res.status;
|
||||
throw error;
|
||||
}
|
||||
return payload?.data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user