From dc6970700b6f85542768de5401feff557ee747ac Mon Sep 17 00:00:00 2001 From: Daniel Bedeleanu Date: Thu, 23 Apr 2026 11:04:11 +0300 Subject: [PATCH] fix(export): use axiosInstance to ensure correct backend URL and auth - Changed useExport.ts to import and use axiosInstance from api.ts - This ensures requests go to port 8918 (backend) not 8919 (frontend) - Removed manual token handling (axiosInstance interceptor handles it) - Removed /api prefix from paths (axiosInstance baseURL has the full URL) - Exported axiosInstance from api.ts for reuse in other modules - Fixes 404 errors caused by requests routing to frontend instead of backend --- frontend/hooks/useExport.ts | 18 +++++++----------- frontend/lib/api.ts | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/frontend/hooks/useExport.ts b/frontend/hooks/useExport.ts index 35599ede..55d1a967 100644 --- a/frontend/hooks/useExport.ts +++ b/frontend/hooks/useExport.ts @@ -1,5 +1,5 @@ import { useState } from "react"; -import axios from "axios"; +import { axiosInstance } from "../lib/api"; interface UseExportReturn { exportSnapshot: (format: "csv" | "xlsx") => Promise; @@ -49,12 +49,10 @@ export function useExport(): UseExportReturn { setError(null); try { - const token = localStorage.getItem('inventory_token'); - const response = await axios.get( - `/api/admin/db/export?format=${format}&type=inventory`, + const response = await axiosInstance.get( + `/admin/db/export?format=${format}&type=inventory`, { - responseType: "blob", - headers: { 'Authorization': `Bearer ${token}` } + responseType: "blob" } ); @@ -84,12 +82,10 @@ export function useExport(): UseExportReturn { setError(null); try { - const token = localStorage.getItem('inventory_token'); - const response = await axios.get( - `/api/admin/db/export?format=${format}&type=audit`, + const response = await axiosInstance.get( + `/admin/db/export?format=${format}&type=audit`, { - responseType: "blob", - headers: { 'Authorization': `Bearer ${token}` } + responseType: "blob" } ); diff --git a/frontend/lib/api.ts b/frontend/lib/api.ts index 623c53cb..f02f7fac 100644 --- a/frontend/lib/api.ts +++ b/frontend/lib/api.ts @@ -57,7 +57,7 @@ export const buildPhotoUrl = (backendUrl: string, photoPath: string): string => * [C-01] Axios instance cu JWT Bearer token în header * și interceptor pentru 401 Unauthorized (token expired) */ -const axiosInstance = axios.create({}); +export const axiosInstance = axios.create({}); axiosInstance.interceptors.request.use(async (config) => { if (!config.baseURL) {