@davoodmehraban89 / Factor-easy / commits / ceef150
Fork 0

سامانه صدور فاکتور و حسابداری

fix(login): report only fixed pending bootstrap stages on real account timeout

davoodmehraban89 committed Oct 12, 2026 at 23:35 UTC ceef15044a6ef5cd57b8c506a4616cef094481ac
1 file changed +41 -6
js/core.js
+41 -6
@@ -67,6 +67,35 @@ function setAuthLoginStatus(message,state){
67 const el=document.getElementById('auth-login-status');
68 if(el){el.textContent=message;el.dataset.state=state||'ready';}
69 }
70 +// Fixed, credential-free bootstrap steps only. Do not collect URLs, user
71 +// identities, payloads, bearer tokens or third-party response bodies.
72 +const FINORA_LOGIN_STEP_LABELS=Object.freeze({
73 + ACCOUNT_CONTEXT:'مشخصات و دسترسی حساب',
74 + PROFILE:'مشخصات کاربر',
75 + ORG_MEMBERSHIP:'عضویت سازمانی',
76 + ORG_ACCESS:'مجوزها و اشتراک سازمان',
77 + APP_ASSETS:'اجزای نرم‌افزار',
78 + TENANT_RECORDS:'اطلاعات شرکت'
79 +});
80 +const finoraPendingLoginReads=new Map();
81 +function finoraPendingLoginStages(){
82 + return [...finoraPendingLoginReads.keys()].sort();
83 +}
84 +function finoraTrackLoginRead(stage,promise){
85 + if(!Object.prototype.hasOwnProperty.call(FINORA_LOGIN_STEP_LABELS,stage))
86 + return Promise.resolve(promise);
87 + finoraPendingLoginReads.set(stage,(finoraPendingLoginReads.get(stage)||0)+1);
88 + return Promise.resolve(promise).finally(()=>{
89 + const count=finoraPendingLoginReads.get(stage)||0;
90 + if(count<=1)finoraPendingLoginReads.delete(stage);
91 + else finoraPendingLoginReads.set(stage,count-1);
92 + });
93 +}
94 +function finoraLoginStageDescription(codes){
95 + const valid=codes.filter(code=>Object.prototype.hasOwnProperty.call(FINORA_LOGIN_STEP_LABELS,code));
96 + return valid.length?valid.map(code=>FINORA_LOGIN_STEP_LABELS[code]).join('، '):'پاسخ درخواست نامشخص';
97 +}
98 +
99 // Abort a stuck read or optional startup barrier without claiming a half-loaded
100 // financial workspace is usable. Only the login hydration path uses this.
101 function finoraAbortableRead(promise,signal){
@@ -101,7 +130,7 @@ function buildUserFromRows(profile,lic){
130 async function fetchCurrentUser(authUser,{signal}={}){
131 let query=sb.from('profiles').select('id,email,username,full_name,role').eq('id',authUser.id);
132 if(signal&&typeof query.abortSignal==='function')query=query.abortSignal(signal);
104 - const p=await finoraAbortableRead(query.single(),signal);
133 + const p=await finoraTrackLoginRead('PROFILE',finoraAbortableRead(query.single(),signal));
134 if(p.error)throw p.error;
135 return buildUserFromRows(p.data,null);
136 }
@@ -273,17 +302,21 @@ async function skipSetPassword(){
302 }
303 async function enterApp(authUser,{timeoutMs=25000}={}){
304 const controller=new AbortController();
276 - const timer=setTimeout(()=>controller.abort(),timeoutMs);
305 + let timeoutStageCodes=[];
306 + const timer=setTimeout(()=>{
307 + timeoutStageCodes=finoraPendingLoginStages(); // capture before aborted promises clear
308 + controller.abort();
309 + },timeoutMs);
310 try{
311 setAuthLoginStatus('در حال بازیابی نشست و آماده‌سازی محیط کار...','loading');
312 const [profile]=await Promise.all([
280 - fetchCurrentUser(authUser,{signal:controller.signal}),
281 - finoraAbortableRead(window.FinoraAppAssetsReady,controller.signal)
313 + finoraTrackLoginRead('ACCOUNT_CONTEXT',fetchCurrentUser(authUser,{signal:controller.signal})),
314 + finoraTrackLoginRead('APP_ASSETS',finoraAbortableRead(window.FinoraAppAssetsReady,controller.signal))
315 ]);
316 if(controller.signal.aborted)throw new Error('FINORA_LOGIN_READ_TIMEOUT');
317 currentUser=profile;
318 setAuthLoginStatus('در حال دریافت اطلاعات شرکت...','loading');
286 - await finoraAbortableRead(pullAll({signal:controller.signal}),controller.signal);
319 + await finoraTrackLoginRead('TENANT_RECORDS',finoraAbortableRead(pullAll({signal:controller.signal}),controller.signal));
320 if(controller.signal.aborted)throw new Error('FINORA_LOGIN_READ_TIMEOUT');
321 const prefs=typeof getMySettings==='function'?getMySettings():null;if(prefs?.user_display_name&&!currentUser.fullName)currentUser.fullName=prefs.user_display_name;if(prefs?.professional_role)currentUser.professionalRole=prefs.professional_role;
322 }catch(err){
@@ -291,7 +324,9 @@ async function enterApp(authUser,{timeoutMs=25000}={}){
324 const timedOut=controller.signal.aborted||err?.message==='FINORA_LOGIN_READ_TIMEOUT';
325 if(timedOut){
326 console.warn('Finora login read timed out (no identity or private data logged).');
294 - setAuthLoginStatus('دریافت اطلاعات حساب بیش از حد طول کشید. اتصال سرور را بررسی کنید و ورود را دوباره انجام دهید.','error');
327 + const stages=timeoutStageCodes.length?timeoutStageCodes:finoraPendingLoginStages();
328 + const safeCodes=stages.length?stages.join(','):'UNKNOWN';
329 + setAuthLoginStatus('دریافت اطلاعات حساب بیش از حد طول کشید. مرحله معطل: '+finoraLoginStageDescription(stages)+' (BOOT_'+safeCodes+'). اتصال را بررسی کنید و دوباره تلاش کنید.','error');
330 }else{
331 console.error('Finora account hydration failed',err);
332 setAuthLoginStatus('دریافت اطلاعات حساب ناموفق بود؛ اتصال را بررسی و دوباره تلاش کنید.','error');