From 65ac4233c2b036ccc9979d5fcc234ae4542915b7 Mon Sep 17 00:00:00 2001 From: GoHorse Deploy Date: Mon, 9 Feb 2026 11:31:30 +0000 Subject: [PATCH] fix(frontend): handle network errors gracefully in auth refresh --- frontend/src/lib/auth.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/src/lib/auth.ts b/frontend/src/lib/auth.ts index 6cbab68..d52779d 100644 --- a/frontend/src/lib/auth.ts +++ b/frontend/src/lib/auth.ts @@ -158,7 +158,14 @@ export async function refreshSession(): Promise { console.log("%c[AUTH] Session restored from cookie", "color: #10b981", user.email); return user; } catch (error) { - console.error("%c[AUTH] Failed to refresh session:", "color: #ef4444", error); + // Only log for non-network errors in development + // "Failed to fetch" is expected when API is unreachable (normal for unauthenticated users) + if (error instanceof TypeError && error.message.includes('Failed to fetch')) { + // Silent fail for network errors - this is expected + console.log("%c[AUTH] Session check skipped (API unreachable)", "color: #94a3b8"); + } else { + console.error("%c[AUTH] Failed to refresh session:", "color: #ef4444", error); + } return null; } } @@ -257,12 +264,12 @@ export async function registerCompany(data: RegisterCompanyData): Promise // Given the previous refactor plan, we probably want to hit an auth registration endpoint that creates both. // Let's check if there is a specific handler for this. // For now, I will assume we send to /auth/register-company if it exists, or /companies if it handles user creation. - + // Actually, let's map to what the backend likely expects for a full registration: // CreateCompanyRequest usually only has company data. // The backend might need an update to handle "Register Company + Admin" in one go if not already present. // Let's stick to the payload structure and verify backend later. - + const payload = { name: data.companyName, slug: data.companyName.toLowerCase().replace(/\s+/g, '-'), // Generate slug @@ -276,7 +283,7 @@ export async function registerCompany(data: RegisterCompanyData): Promise state: data.state, description: data.description, years_in_market: data.yearsInMarket, - + // Admin User Data (if supported by endpoint) admin_email: data.email, admin_password: data.password, // Keep for backward compatibility if needed