From c81d4808442b161c148dc7e23297fabde8e60e9f Mon Sep 17 00:00:00 2001 From: ManthanNimodiya Date: Mon, 8 Jun 2026 06:35:35 +0530 Subject: [PATCH 1/2] fix(auth): make plan and org fetches non-fatal, always persist auth with updated timestamp --- apps/desktop/src-tauri/src/auth.rs | 53 +++++++++++++----------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/apps/desktop/src-tauri/src/auth.rs b/apps/desktop/src-tauri/src/auth.rs index e179609f590..3f640757a70 100644 --- a/apps/desktop/src-tauri/src/auth.rs +++ b/apps/desktop/src-tauri/src/auth.rs @@ -70,45 +70,38 @@ impl AuthStore { } let mut auth = auth; - println!( - "Fetching plan for user {}", - auth.user_id.as_deref().unwrap_or("unknown") - ); - let response = app + + match app .authed_api_request("/api/desktop/plan", |client, url| client.get(url)) .await - .map_err(|e| { - println!("Failed to fetch plan: {e}"); - e.to_string() - })?; - println!("Plan fetch response status: {}", response.status()); - - if !response.status().is_success() { - let error_msg = format!("Failed to fetch plan: {}", response.status()); - return Err(error_msg); - } - - #[derive(Deserialize)] - struct Response { - upgraded: bool, + { + Ok(response) if response.status().is_success() => { + #[derive(Deserialize)] + struct PlanResponse { + upgraded: bool, + } + match response.json::().await { + Ok(plan_response) => { + auth.plan = Some(Plan { + upgraded: plan_response.upgraded, + last_checked: chrono::Utc::now().timestamp() as i32, + manual: auth.plan.as_ref().is_some_and(|p| p.manual), + }); + } + Err(e) => tracing::warn!("Failed to parse plan response: {e}"), + } + } + Ok(response) => tracing::warn!("Plan fetch returned {}", response.status()), + Err(e) => tracing::warn!("Failed to fetch plan: {e}"), } - let plan_response: Response = response.json().await.map_err(|e| e.to_string())?; - - auth.plan = Some(Plan { - upgraded: plan_response.upgraded, - last_checked: chrono::Utc::now().timestamp() as i32, - manual: auth.plan.as_ref().is_some_and(|p| p.manual), - }); match api::fetch_organizations(app).await { Ok(orgs) => { auth.organizations = orgs; - auth.organizations_updated_at = Some(chrono::Utc::now().timestamp() as i32); - } - Err(e) => { - tracing::warn!("Failed to fetch organizations: {e}"); } + Err(e) => tracing::warn!("Failed to fetch organizations: {e}"), } + auth.organizations_updated_at = Some(chrono::Utc::now().timestamp() as i32); Self::set(app, Some(auth))?; From ec233e7387d4c12bf0f2e60c55ceebec2157ca37 Mon Sep 17 00:00:00 2001 From: ManthanNimodiya Date: Mon, 8 Jun 2026 07:04:02 +0530 Subject: [PATCH 2/2] fix(auth): only stamp org timestamp on failure when orgs list is empty --- apps/desktop/src-tauri/src/auth.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src-tauri/src/auth.rs b/apps/desktop/src-tauri/src/auth.rs index 3f640757a70..5ae16506dba 100644 --- a/apps/desktop/src-tauri/src/auth.rs +++ b/apps/desktop/src-tauri/src/auth.rs @@ -98,10 +98,15 @@ impl AuthStore { match api::fetch_organizations(app).await { Ok(orgs) => { auth.organizations = orgs; + auth.organizations_updated_at = Some(chrono::Utc::now().timestamp() as i32); + } + Err(e) => { + tracing::warn!("Failed to fetch organizations: {e}"); + if auth.organizations.is_empty() { + auth.organizations_updated_at = Some(chrono::Utc::now().timestamp() as i32); + } } - Err(e) => tracing::warn!("Failed to fetch organizations: {e}"), } - auth.organizations_updated_at = Some(chrono::Utc::now().timestamp() as i32); Self::set(app, Some(auth))?;