fix: store login crash and dashboard misrouted as storefront
Some checks failed
CI / ruff (push) Successful in 10s
CI / pytest (push) Failing after 44m20s
CI / validate (push) Successful in 22s
CI / dependency-scanning (push) Successful in 27s
CI / docs (push) Has been skipped
CI / deploy (push) Has been skipped

- Seed default RBAC roles per store and assign role_id to StoreUser
  records (was never implemented after RBAC Phase 1 cleanup)
- Handle nullable role in auth_service find_user_store and
  get_user_store_role to prevent NoneType crash on login
- Use platform_clean_path instead of clean_path in FrontendTypeMiddleware
  so /store/X/dashboard is detected as STORE, not STOREFRONT

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 01:19:22 +01:00
parent 05d31a7fc5
commit cd935988c4
3 changed files with 61 additions and 7 deletions

View File

@@ -43,8 +43,11 @@ class FrontendTypeMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request: Request, call_next):
"""Detect frontend type and inject into request state."""
host = request.headers.get("host", "")
# Use clean_path if available (from store_context_middleware), else original path
path = getattr(request.state, "clean_path", None) or request.url.path
# Use platform_clean_path (platform prefix stripped, store prefix retained)
# so FrontendDetector can distinguish /store/ from /storefront/.
# Do NOT use clean_path here — it has the store prefix stripped too,
# which makes /store/X/dashboard indistinguishable from /storefront/X/products.
path = getattr(request.state, "platform_clean_path", None) or request.url.path
# Check if store context exists (set by StoreContextMiddleware)
has_store_context = (