fix(frontend): handle network errors gracefully in auth refresh
This commit is contained in:
parent
e1638f9275
commit
65ac4233c2
1 changed files with 11 additions and 4 deletions
|
|
@ -158,7 +158,14 @@ export async function refreshSession(): Promise<User | null> {
|
||||||
console.log("%c[AUTH] Session restored from cookie", "color: #10b981", user.email);
|
console.log("%c[AUTH] Session restored from cookie", "color: #10b981", user.email);
|
||||||
return user;
|
return user;
|
||||||
} catch (error) {
|
} 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;
|
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.
|
// 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.
|
// 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.
|
// 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:
|
// Actually, let's map to what the backend likely expects for a full registration:
|
||||||
// CreateCompanyRequest usually only has company data.
|
// CreateCompanyRequest usually only has company data.
|
||||||
// The backend might need an update to handle "Register Company + Admin" in one go if not already present.
|
// 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.
|
// Let's stick to the payload structure and verify backend later.
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
name: data.companyName,
|
name: data.companyName,
|
||||||
slug: data.companyName.toLowerCase().replace(/\s+/g, '-'), // Generate slug
|
slug: data.companyName.toLowerCase().replace(/\s+/g, '-'), // Generate slug
|
||||||
|
|
@ -276,7 +283,7 @@ export async function registerCompany(data: RegisterCompanyData): Promise<void>
|
||||||
state: data.state,
|
state: data.state,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
years_in_market: data.yearsInMarket,
|
years_in_market: data.yearsInMarket,
|
||||||
|
|
||||||
// Admin User Data (if supported by endpoint)
|
// Admin User Data (if supported by endpoint)
|
||||||
admin_email: data.email,
|
admin_email: data.email,
|
||||||
admin_password: data.password, // Keep for backward compatibility if needed
|
admin_password: data.password, // Keep for backward compatibility if needed
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue