From 7feacd5af8dfdd1ecc1a510a8ae465c84c10c516 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Sun, 8 Feb 2026 20:30:16 +0100 Subject: [PATCH] fix(routing): fix store login 404 caused by CMS catch-all route priority The CMS catch-all route /{store_code}/{slug} was registered before tenancy's /{store_code}/login because modules are discovered alphabetically (cms before tenancy). Also fix login.js store code extraction for /platforms/{code}/store/... URL pattern. - Add ROUTE_CONFIG priority=100 to CMS store pages so catch-all registers last - Sort get_store_page_routes() by priority (matching other route getters) - Use indexOf('store') in login.js to support platform-prefixed URLs Co-Authored-By: Claude Opus 4.6 --- app/modules/cms/routes/pages/store.py | 9 ++++++++- app/modules/routes.py | 11 +++++++++-- app/modules/tenancy/static/store/js/login.js | 6 ++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/modules/cms/routes/pages/store.py b/app/modules/cms/routes/pages/store.py index c41fed33..d161cbbf 100644 --- a/app/modules/cms/routes/pages/store.py +++ b/app/modules/cms/routes/pages/store.py @@ -22,6 +22,11 @@ logger = logging.getLogger(__name__) router = APIRouter() +# Route configuration - high priority so catch-all is registered last +ROUTE_CONFIG = { + "priority": 100, +} + # ============================================================================ # HELPER: Build Store Dashboard Context @@ -176,11 +181,13 @@ async def store_content_page( ) store = getattr(request.state, "store", None) + platform = getattr(request.state, "platform", None) store_id = store.id if store else None + platform_id = platform.id if platform else 1 # Load content page from database (store override → platform default) page = content_page_service.get_page_for_store( - db, slug=slug, store_id=store_id, include_unpublished=False + db, platform_id=platform_id, slug=slug, store_id=store_id, include_unpublished=False ) if not page: diff --git a/app/modules/routes.py b/app/modules/routes.py index 5d71ceb6..5ee7c909 100644 --- a/app/modules/routes.py +++ b/app/modules/routes.py @@ -286,8 +286,15 @@ def get_page_routes() -> list[RouteInfo]: def get_store_page_routes() -> list[RouteInfo]: - """Get store page routes from modules.""" - return [r for r in discover_module_routes() if r.route_type == "pages" and r.frontend == "store"] + """ + Get store page routes from modules, sorted by priority. + + Returns routes sorted by priority (lower first, higher last). + This ensures catch-all routes (priority 100+) are registered after + specific routes. + """ + routes = [r for r in discover_module_routes() if r.route_type == "pages" and r.frontend == "store"] + return sorted(routes, key=lambda r: r.priority) def get_admin_page_routes() -> list[RouteInfo]: diff --git a/app/modules/tenancy/static/store/js/login.js b/app/modules/tenancy/static/store/js/login.js index c1f6ace2..88631864 100644 --- a/app/modules/tenancy/static/store/js/login.js +++ b/app/modules/tenancy/static/store/js/login.js @@ -39,9 +39,11 @@ function storeLogin() { storeLoginLog.debug('Dark mode:', this.dark); // Get store code from URL path + // Supports both /store/{code}/login and /platforms/{platform}/store/{code}/login const pathSegments = window.location.pathname.split('/').filter(Boolean); - if (pathSegments[0] === 'store' && pathSegments[1]) { - this.storeCode = pathSegments[1]; + const storeIndex = pathSegments.indexOf('store'); + if (storeIndex !== -1 && pathSegments[storeIndex + 1]) { + this.storeCode = pathSegments[storeIndex + 1]; storeLoginLog.debug('Store code from URL:', this.storeCode); await this.loadStore(); }