Se soluciono autenticacion

This commit is contained in:
2025-08-05 13:06:24 -06:00
parent c280afe646
commit c9df4e3ab2
21 changed files with 758 additions and 624 deletions

View File

@@ -1,4 +1,5 @@
import React, { useEffect, useState } from 'react';
import { fetchWithAuth, postWithAuth, putWithAuth, deleteWithAuth } from '../fetchWithAuth';
const API_URL = import.meta.env.VITE_EFC_API_URL;
export default function Vucem() {
@@ -118,10 +119,7 @@ export default function Vucem() {
const fetchVucem = async () => {
setLoading(true);
try {
const token = localStorage.getItem('access');
const res = await fetch(`${API_URL}/vucem/vucem/`, {
headers: token ? { 'Authorization': `Bearer ${token}` } : {},
});
const res = await fetchWithAuth(`${API_URL}/vucem/vucem/`);
if (!res.ok) throw new Error('Error al cargar VUCEM');
const data = await res.json();
setVucemList(data);
@@ -135,10 +133,7 @@ export default function Vucem() {
// Funciones de descarga
const downloadCertificate = async (id, usuario) => {
try {
const token = localStorage.getItem('access');
const res = await fetch(`${API_URL}/vucem/vucem/${id}/download_cer/`, {
headers: token ? { 'Authorization': `Bearer ${token}` } : {},
});
const res = await fetchWithAuth(`${API_URL}/vucem/vucem/${id}/download_cer/`);
if (!res.ok) {
if (res.status === 404) {
@@ -171,10 +166,7 @@ export default function Vucem() {
const downloadKey = async (id, usuario) => {
try {
const token = localStorage.getItem('access');
const res = await fetch(`${API_URL}/vucem/vucem/${id}/download_key/`, {
headers: token ? { 'Authorization': `Bearer ${token}` } : {},
});
const res = await fetchWithAuth(`${API_URL}/vucem/vucem/${id}/download_key/`);
if (!res.ok) {
if (res.status === 404) {
@@ -939,12 +931,7 @@ export default function Vucem() {
formData.append('acuseedocument', form.acuseedocument);
formData.append('is_active', form.is_active);
try {
const token = localStorage.getItem('access');
const res = await fetch(`${API_URL}/vucem/vucem/`, {
method: 'POST',
headers: token ? { 'Authorization': `Bearer ${token}` } : {},
body: formData,
});
const res = await postWithAuth(`${API_URL}/vucem/vucem/`, formData);
if (!res.ok) throw new Error('Error al crear VUCEM');
await fetchVucem();
closeModals();
@@ -1108,12 +1095,7 @@ export default function Vucem() {
formData.append('acuseedocument', form.acuseedocument);
formData.append('is_active', form.is_active);
try {
const token = localStorage.getItem('access');
const res = await fetch(`${API_URL}/vucem/vucem/${editVucem.id}/`, {
method: 'PATCH',
headers: token ? { 'Authorization': `Bearer ${token}` } : {},
body: formData,
});
const res = await putWithAuth(`${API_URL}/vucem/vucem/${editVucem.id}/`, formData);
if (!res.ok) throw new Error('Error al actualizar VUCEM');
await fetchVucem();
closeModals();
@@ -1273,11 +1255,7 @@ export default function Vucem() {
<button type="button" onClick={async () => {
if (!deleteVucem) return;
try {
const token = localStorage.getItem('access');
const res = await fetch(`${API_URL}/vucem/vucem/${deleteVucem.id}/`, {
method: 'DELETE',
headers: token ? { 'Authorization': `Bearer ${token}` } : {},
});
const res = await deleteWithAuth(`${API_URL}/vucem/vucem/${deleteVucem.id}/`);
if (!res.ok) throw new Error('Error al eliminar VUCEM');
await fetchVucem();
closeModals();