fix(auth): inventoryApi - use apiFetch with /backend prefix and Authorization header
This commit is contained in:
@@ -1,14 +1,13 @@
|
|||||||
|
import { apiFetch } from './api';
|
||||||
import type { EntityResponse, InventoryTreeNode, ListResponse, NodeContext, Relation } from '../types/inventory';
|
import type { EntityResponse, InventoryTreeNode, ListResponse, NodeContext, Relation } from '../types/inventory';
|
||||||
|
|
||||||
async function handleResponse<T>(response: Response): Promise<T> {
|
async function handleResponse<T>(response: Response): Promise<T> {
|
||||||
if (!response.ok) {
|
if (!response.ok) throw new Error(`API error: ${response.status}`);
|
||||||
throw new Error(`API error: ${response.status}`);
|
|
||||||
}
|
|
||||||
return response.json() as Promise<T>;
|
return response.json() as Promise<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchJson<T>(url: string): Promise<T> {
|
async function fetchJson<T>(path: string): Promise<T> {
|
||||||
const response = await fetch(url, { cache: 'no-store' });
|
const response = await apiFetch(path, { cache: 'no-store' });
|
||||||
return handleResponse<T>(response);
|
return handleResponse<T>(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user