From 2fc157d7b227c6de13cd59945852bae07c5d4e10 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Mon, 23 Feb 2026 13:53:31 +0100 Subject: [PATCH] fix: store menu 404, logger crash, platform detection, and sidebar UX - Fix store menu API URL (/store/menu/render/store, not /store/core/...) - Fix storeLog/merchantLog fallback to console object instead of console.log - Embed platform_id/platform_code in store JWT from URL context at login - Use token_platform_id in store menu endpoint with DB fallback for old tokens - Add "Menu unavailable" warning in sidebar fallback for all three frontends - Standardize admin section default to all-open (consistent with store/merchant) Co-Authored-By: Claude Opus 4.6 --- app/modules/core/routes/api/store_menu.py | 6 ++++-- app/modules/core/static/admin/js/init-alpine.js | 2 +- app/modules/core/static/merchant/js/init-alpine.js | 2 +- app/modules/core/static/store/js/init-alpine.js | 4 ++-- app/modules/tenancy/routes/api/store_auth.py | 8 ++++++++ app/templates/admin/partials/sidebar.html | 6 +++++- app/templates/merchant/partials/sidebar.html | 7 ++++++- app/templates/store/partials/sidebar.html | 7 ++++++- 8 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app/modules/core/routes/api/store_menu.py b/app/modules/core/routes/api/store_menu.py index f6dad459..22bf5053 100644 --- a/app/modules/core/routes/api/store_menu.py +++ b/app/modules/core/routes/api/store_menu.py @@ -95,8 +95,10 @@ async def get_rendered_store_menu( # Get the store from the JWT token's store context store = store_service.get_store_by_id(db, current_user.token_store_id) - # Resolve the store's platform via service layer - platform_id = menu_service.get_store_primary_platform_id(db, store.id) + # Platform from JWT (set at login from URL context), fall back to DB for old tokens + platform_id = current_user.token_platform_id + if platform_id is None: + platform_id = menu_service.get_store_primary_platform_id(db, store.id) # Get filtered menu with platform visibility and store_code interpolation menu = menu_service.get_menu_for_rendering( diff --git a/app/modules/core/static/admin/js/init-alpine.js b/app/modules/core/static/admin/js/init-alpine.js index 2e774abc..7702c3aa 100644 --- a/app/modules/core/static/admin/js/init-alpine.js +++ b/app/modules/core/static/admin/js/init-alpine.js @@ -214,7 +214,7 @@ function data() { // Initialize openSections for new sections (default: first section open) if (this.openSections[section.id] === undefined) { // Default: first section open, rest closed - this.openSections[section.id] = (sections.indexOf(section) === 0); + this.openSections[section.id] = true; } } console.debug('Menu config loaded:', this.visibleMenuItems.size, 'items'); diff --git a/app/modules/core/static/merchant/js/init-alpine.js b/app/modules/core/static/merchant/js/init-alpine.js index c52a7dfb..aa7f4c8a 100644 --- a/app/modules/core/static/merchant/js/init-alpine.js +++ b/app/modules/core/static/merchant/js/init-alpine.js @@ -5,7 +5,7 @@ */ // Use centralized logger (guarded: log-config.js loads with defer, so it may not be ready yet) -const merchantLog = (window.LogConfig && window.LogConfig.log) || console.log; +const merchantLog = (window.LogConfig && window.LogConfig.log) || console; console.log('[MERCHANT INIT-ALPINE] Loading...'); diff --git a/app/modules/core/static/store/js/init-alpine.js b/app/modules/core/static/store/js/init-alpine.js index 33a8d335..81dadf4b 100644 --- a/app/modules/core/static/store/js/init-alpine.js +++ b/app/modules/core/static/store/js/init-alpine.js @@ -5,7 +5,7 @@ */ // Use centralized logger (guarded: log-config.js loads with defer, so it may not be ready yet) -const storeLog = (window.LogConfig && window.LogConfig.log) || console.log; +const storeLog = (window.LogConfig && window.LogConfig.log) || console; console.log('[STORE INIT-ALPINE] Loading...'); @@ -129,7 +129,7 @@ function data() { this.menuLoading = true; try { - this.menuData = await apiClient.get('/store/core/menu/render/store'); + this.menuData = await apiClient.get('/store/menu/render/store'); // Initialize section open state from response for (const section of (this.menuData?.sections || [])) { if (this.openSections[section.id] === undefined) { diff --git a/app/modules/tenancy/routes/api/store_auth.py b/app/modules/tenancy/routes/api/store_auth.py index d0628dfa..7f4a3750 100644 --- a/app/modules/tenancy/routes/api/store_auth.py +++ b/app/modules/tenancy/routes/api/store_auth.py @@ -27,6 +27,7 @@ from app.modules.tenancy.models.user_password_reset_token import ( UserPasswordResetToken, # noqa: API-007 ) from app.modules.tenancy.services.user_auth_service import user_auth_service +from middleware.platform_context import get_current_platform from middleware.store_context import get_current_store from models.schema.auth import LogoutResponse, StoreUserResponse, UserContext, UserLogin @@ -110,12 +111,19 @@ def store_login( f"for store {store.store_code} as {store_role}" ) + # Get platform from URL context (middleware-detected) + platform = get_current_platform(request) + platform_id = platform.id if platform else None + platform_code = platform.code if platform else None + # Create store-scoped access token with store information token_data = auth_service.auth_manager.create_access_token( user=user, store_id=store.id, store_code=store.store_code, store_role=store_role, + platform_id=platform_id, + platform_code=platform_code, ) # Set HTTP-only cookie for browser navigation diff --git a/app/templates/admin/partials/sidebar.html b/app/templates/admin/partials/sidebar.html index 9ca7a027..cc141919 100644 --- a/app/templates/admin/partials/sidebar.html +++ b/app/templates/admin/partials/sidebar.html @@ -88,7 +88,11 @@ -

Loading menu...

+
+

+ Menu unavailable. Showing default items only. +

+
{% endmacro %} diff --git a/app/templates/merchant/partials/sidebar.html b/app/templates/merchant/partials/sidebar.html index 5323a6eb..9090c33d 100644 --- a/app/templates/merchant/partials/sidebar.html +++ b/app/templates/merchant/partials/sidebar.html @@ -86,7 +86,7 @@ - +
  • @@ -99,6 +99,11 @@
+
+

+ Menu unavailable. Showing default items only. +

+
{% endmacro %} diff --git a/app/templates/store/partials/sidebar.html b/app/templates/store/partials/sidebar.html index 8e1df7bd..c910af79 100644 --- a/app/templates/store/partials/sidebar.html +++ b/app/templates/store/partials/sidebar.html @@ -86,7 +86,7 @@ - +
  • @@ -99,6 +99,11 @@
+
+

+ Menu unavailable. Showing default items only. +

+