@davoodmehraban89 / Factor-easy / commits / 7d054df
Fork 0

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

fix(auth): remove dependency on missing #menu-admin-panel element that crashed enterApp and left app empty after login

The Phase 1 shell redesign removed the #menu-admin-panel element, but enterApp() (core.js) and canShowShellCommand() (ui.js) still used it. enterApp threw a TypeError after the auth screen was hidden, so refreshAllSurfaces() never ran and no data was rendered. - core.js: admin visibility now derives from currentUser.role; post-login UI steps are null-safe and isolated so one failing render can not blank the whole app. - ui.js: canShowShellCommand() checks currentUser.role instead of a DOM element (also restores the admin users/licenses menu entry).

davoodmehraban89 committed Sep 29, 2026 at 15:09 UTC 7d054dfa24ef0638c490861d1b57ce16a5abb6ed
2 files changed +13 -9
js/core.js
+10 -5
@@ -213,11 +213,16 @@ async function enterApp(authUser){
213 showAuthPanel('main');
214 return;
215 }
216 - document.getElementById('auth-screen').style.display='none';
217 - document.getElementById('logged-user-label').innerText='کاربر: '+(currentUser.fullName||currentUser.email||currentUser.username)+(currentUser.role==='admin'?' (مدیر سیستم)':'');
218 - document.getElementById('menu-admin-panel').style.display=(currentUser.role==='admin')?'block':'none';
219 - refreshAllSurfaces();
220 - maybeMigrateLegacyData();
216 + // Post-login UI. Every step is null-safe / isolated so that one missing element or one failing
217 + // render can never abort the rest and leave the app empty (previous bug: #menu-admin-panel).
218 + const authScreen=document.getElementById('auth-screen');
219 + if(authScreen)authScreen.style.display='none';
220 + const userLabel=document.getElementById('logged-user-label');
221 + if(userLabel)userLabel.innerText='کاربر: '+(currentUser.fullName||currentUser.email||currentUser.username)+(currentUser.role==='admin'?' (مدیر سیستم)':'');
222 + // Admin visibility is derived from the verified role (see canShowShellCommand in ui.js), not from a DOM element.
223 + document.body.classList.toggle('is-admin',currentUser.role==='admin');
224 + try{refreshAllSurfaces();}catch(e){console.error('refreshAllSurfaces failed',e);}
225 + try{maybeMigrateLegacyData();}catch(e){console.error('maybeMigrateLegacyData failed',e);}
226 }
227 async function handleLogout(){
228 if(syncPending&&!confirm('تغییرات ذخیره‌نشده وجود دارد. با خروج ممکن است از بین برود. خارج شوم؟'))return;
js/ui.js
+3 -4
@@ -76,10 +76,9 @@ const FINORA_VIEW_HOME={
76 const FINORA_COMMANDS=Object.entries(FINORA_MODULES).flatMap(([module,m])=>m.groups.flatMap(g=>g.items.map(i=>({module,moduleTitle:m.title,title:i[0],view:i[1],icon:i[2],guard:i[3]||''}))));
77
78 function canShowShellCommand(cmd){
79 - if(cmd.guard==='admin'){
80 - const el=document.getElementById('menu-admin-panel');
81 - return !!el&&el.style.display!=='none';
82 - }
79 + // Admin-only entries are shown based on the verified role of the signed-in user
80 + // (server-side RLS/RPC still enforces the real permission).
81 + if(cmd.guard==='admin')return !!(typeof currentUser!=='undefined'&&currentUser&&currentUser.role==='admin');
82 return true;
83 }
84 function renderModulePanel(moduleKey,activeView){