From 9baa5612dedcb0a5d212d1c0d4cd2302e3e22cc7 Mon Sep 17 00:00:00 2001 From: Daniel Bedeleanu Date: Fri, 17 Apr 2026 12:28:44 +0300 Subject: [PATCH] fix: resolve onboarding network error by using authenticated user context Issue: createItem was using hardcoded userId: 1 without checking if currentUser was authenticated. Backend requires Bearer token from authenticated user, not userId parameter. Changes: - Use currentUser.id instead of hardcoded 1 - Check currentUser exists before attempting cloud sync - Add error handling for cloud sync failures - Graceful fallback to local-only save if not authenticated Resolves 'Network Error' during onboarding item creation. --- frontend/app/page.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index 3eb22bd8..dd50f739 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -165,11 +165,18 @@ export default function Home() { await db.items.add(itemData); // 2. If online, try to push to backend immediately - if (isOnline) { - await inventoryApi.createItem(1, itemData); - toast.success("Item saved to cloud catalog!"); - } else { + if (isOnline && currentUser) { + try { + await inventoryApi.createItem(currentUser.id, itemData); + toast.success("Item saved to cloud catalog!"); + } catch (err: any) { + console.error("Cloud sync failed:", err.message); + toast.error("Item saved locally. Cloud sync failed."); + } + } else if (!isOnline) { toast.success("Item saved locally. Will sync when online."); + } else { + toast("Please log in to save to cloud.", { icon: '⚠️' }); } setShowOnboarding(false);