From cc0270326ee4742e2ea2874788bd98bd08e0d991 Mon Sep 17 00:00:00 2001 From: SuperDooper <37051355+superdooper86@users.noreply.github.com> Date: Fri, 8 May 2026 16:00:00 +0200 Subject: [PATCH] fix: add /api/organizations + personal /api/usage fallbacks in login JS --- windows/LoginWindow.xaml.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/windows/LoginWindow.xaml.cs b/windows/LoginWindow.xaml.cs index b6ac3dc..f64c14c 100644 --- a/windows/LoginWindow.xaml.cs +++ b/windows/LoginWindow.xaml.cs @@ -71,12 +71,21 @@ public partial class LoginWindow : Window try { const string script = @"(async()=>{try{ - const b=await(await fetch('/api/bootstrap',{headers:{accept:'application/json'}})).json(); - const id=b?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid - ||b?.default_organization?.uuid||null; + const h={headers:{accept:'application/json'}}; + const b=await(await fetch('/api/bootstrap',h)).json(); + let id=b?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid + ||b?.default_organization?.uuid||null; const e=b?.account?.email_address||b?.account?.email||b?.email||null; - if(!id)return{email:e,orgId:null,usage:null}; - const u=await(await fetch('/api/organizations/'+id+'/usage',{headers:{accept:'application/json'}})).json(); + if(!id){ + try{const ol=await(await fetch('/api/organizations',h)).json(); + if(Array.isArray(ol)&&ol.length>0)id=ol[0]?.uuid||null;}catch(e2){} + } + if(!id){ + try{const pu=await(await fetch('/api/usage',h)).json(); + if(pu&&!pu.error)return{email:e,orgId:null,usage:pu};}catch(e3){} + return{email:e,orgId:null,usage:null}; + } + const u=await(await fetch('/api/organizations/'+id+'/usage',h)).json(); return{email:e,orgId:id,usage:u}; }catch(ex){return{error:String(ex)};}})()";