سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 10:30 UTC
fix: defer account license read until organization context is installed
davoodmehraban89 committed
Oct 14, 2026 at 23:45 UTC
2562f0a945de47b2c52629fb56f48d9d0dd069df
1 file changed
+19
-3
js/core.js
+19
-3
@@ -62,6 +62,11 @@ let authBusy=false;
62
let finoraAppAssetsResolve,finoraAppAssetsReject;
63
window.FinoraAppAssetsReady=new Promise((resolve,reject)=>{finoraAppAssetsResolve=resolve;finoraAppAssetsReject=reject;});
64
window.FinoraAppAssetsReady.catch(()=>{});
65
+// The account entitlement lookup MUST NOT race the organization module's
66
+// fetchCurrentUser wrapper. Do not stall the separate interactive login form.
67
+let finoraOrganizationContextResolve;
68
+window.FinoraOrganizationContextReady=new Promise(resolve=>{finoraOrganizationContextResolve=resolve;});
69
+window.finoraMarkOrganizationContextReady=()=>finoraOrganizationContextResolve();
70
window.finoraMarkAppAssetsReady=()=>finoraAppAssetsResolve();
71
window.finoraMarkAppAssetsFailed=()=>finoraAppAssetsReject(new Error('FINORA_APP_ASSETS_UNAVAILABLE'));
72
@@ -321,8 +326,15 @@ async function enterApp(authUser,{timeoutMs=25000}={}){
326
},timeoutMs);
327
try{
328
setAuthLoginStatus('در حال بازیابی نشست و آمادهسازی محیط کار...','loading');
329
+ // Waiting for ALL assets in parallel was not sufficient: the old account
330
+ // lookup could resolve BEFORE organization-rbac.js installed its wrapper,
331
+ // leaving a placeholder 'unavailable' license until the next login.
332
+ const organizationAccount=window.FinoraOrganizationContextReady.then(()=>{
333
+ if(controller.signal.aborted)throw new Error('FINORA_LOGIN_READ_TIMEOUT');
334
+ return fetchCurrentUser(authUser,{signal:controller.signal});
335
+ });
336
const [profile]=await Promise.all([
325
- finoraTrackLoginRead('ACCOUNT_CONTEXT',finoraAbortableRead(fetchCurrentUser(authUser,{signal:controller.signal}),controller.signal)),
337
+ finoraTrackLoginRead('ACCOUNT_CONTEXT',finoraAbortableRead(organizationAccount,controller.signal)),
338
finoraTrackLoginRead('APP_ASSETS',finoraAbortableRead(window.FinoraAppAssetsReady,controller.signal))
339
]);
340
if(controller.signal.aborted)throw new Error('FINORA_LOGIN_READ_TIMEOUT');
@@ -395,9 +407,13 @@ function updateLicenseDisplay(user){
407
if(hasActiveLicense){
408
badge.className='badge badge-success';
409
badge.innerText=(sub.type==='lifetime')?'وضعیت اشتراک : نامحدود':`وضعیت اشتراک : تا تاریخ ${formatToJalali(sub.endDate)}`;
398
- }else if(isExpired||sub.status==='cancelled'){
410
+ }else if(sub.status==='cancelled'||sub.status==='expired'||(sub.status==='active'&&isExpired)){
411
badge.className='badge badge-danger';badge.innerText='وضعیت اشتراک : منقضی شده';
400
- }else{
412
+ }else if(sub.status==='trial'||sub.type==='trial'){
413
badge.className='badge badge-warning';badge.innerText=`وضعیت اشتراک : آزمایشی تا تاریخ ${formatToJalali(sub.endDate)}`;
414
+ }else{
415
+ // A failed/unfinished organization lookup is NOT evidence of expiry.
416
+ // Fail closed for writes via canWrite(), but label the cause truthfully.
417
+ badge.className='badge badge-warning';badge.innerText='وضعیت اشتراک : قابل بررسی نیست';
418
}
419
}