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 @@
// src/api/pedimentoDocuments.ts
import { fetchWithAuth } from '../fetchWithAuth';
export interface PedimentoDocument {
id: string;
@@ -19,26 +20,25 @@ export interface PedimentoDocumentsResponse {
results: PedimentoDocument[];
}
const API_URL = import.meta.env.VITE_EFC_API_URL;
const API_URL = (import.meta as any).env.VITE_EFC_API_URL;
export async function fetchPedimentoDocuments(
token: string,
pedimentoId: string,
page: number = 1,
pageSize: number = 10
): Promise<PedimentoDocumentsResponse> {
const res = await fetch(
`${API_URL}/record/documents/?page=${page}&page_size=${pageSize}&pedimento=${pedimentoId}`,
{
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
try {
const res = await fetchWithAuth(
`${API_URL}/record/documents/?page=${page}&page_size=${pageSize}&pedimento=${pedimentoId}`
);
if (!res.ok) {
throw new Error('No autorizado o error en la petición');
}
);
if (res.status === 401) {
throw new Error('SESSION_EXPIRED');
return res.json();
} catch (error) {
console.error('Error in fetchPedimentoDocuments:', error);
throw error;
}
if (!res.ok) throw new Error('No autorizado o error en la petición');
return res.json();
}