fix(frontend): handle network errors gracefully in auth refresh

This commit is contained in:
GoHorse Deploy 2026-02-09 11:31:30 +00:00
parent e1638f9275
commit 65ac4233c2

View file

@ -158,7 +158,14 @@ export async function refreshSession(): Promise<User | null> {
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<void>
// 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<void>
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