feat: integrate authFetch for API calls in InventoryView and PantryView, and add pantry route with authentication

This commit is contained in:
Nils-Johan Gynther
2026-04-21 14:49:20 +02:00
parent 81b63b3fdb
commit c57f4bde19
3 changed files with 22 additions and 5 deletions
@@ -4,19 +4,21 @@ import { useState, useEffect, useCallback } from 'react';
import type { InventoryItem, Product } from '../../../../features/inventory/types';
import InventoryList from '../../../inventory/InventoryList';
import InventoryForm from '../../../inventory/InventoryForm';
import { useAuthFetch } from '../../../../lib/use-auth-fetch';
export default function InventoryView() {
const [inventory, setInventory] = useState<InventoryItem[]>([]);
const [products, setProducts] = useState<Product[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const authFetch = useAuthFetch();
const load = useCallback(async () => {
setLoading(true);
setError(null);
try {
const [invRes, prodRes] = await Promise.all([
fetch('/api/inventory'),
authFetch('/api/inventory'),
fetch('/api/products'),
]);
if (!invRes.ok) throw new Error('Kunde inte hämta inventarie');
@@ -29,7 +31,7 @@ export default function InventoryView() {
} finally {
setLoading(false);
}
}, []);
}, [authFetch]);
useEffect(() => { load(); }, [load]);