Skip to content

fix(sync): admin lists empty on some hosts β€” serve /api/collections via web session (#193)#203

Closed
jakub-przepiora wants to merge 1 commit into
mainfrom
fix/collections-session-auth-193
Closed

fix(sync): admin lists empty on some hosts β€” serve /api/collections via web session (#193)#203
jakub-przepiora wants to merge 1 commit into
mainfrom
fix/collections-session-auth-193

Conversation

@jakub-przepiora

@jakub-przepiora jakub-przepiora commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Problem (discussion #193)

On some deployments admin list pages (work orders, lines, product types, …) render empty even though the data exists β€” you can pick a line in the work-order form and save it, the planner shows sample data, but the lists stay blank.

Root cause

The lists are fed by a live-sync snapshot GET /api/collections/{name}. It lived in the api route group and authenticated via Sanctum stateful-domain matching (Origin/Referer vs the app host). Behind a reverse proxy, or when APP_URL doesn't cover the host the app is actually served on, that check fails β†’ snapshot returns 401 β†’ the frontend silently swallows the error into an empty list, while the rest of the SPA (session-cookie based, like the planner) keeps working.

Fix

  • Move the route to the web group so it authenticates with the plain session cookie, exactly like every Inertia page β€” host-independent, no SANCTUM_STATEFUL_DOMAINS tuning. URL unchanged (GET /api/collections/{name}); mobile/token clients unaffected (/api/v1/*).
  • realtimeCollection now logs a console warning on snapshot failure instead of failing silently.

Tests

  • New CollectionSnapshotSessionAuthTest: authenticated session gets the snapshot (no Origin/stateful needed), guest β†’ 401, unknown shape β†’ 404.
  • Existing StatefulCollectionAccessTest kept (config still valid for other /api routes).
  • Full suite green (1925).

πŸ€– Generated with claude-flow

Summary by CodeRabbit

  • Bug Fixes

    • Fixed empty admin live-sync lists when existing data was available.
    • Improved session-based authentication for live-sync snapshot requests.
    • Added a warning when snapshot loading fails instead of failing silently.
  • Tests

    • Added coverage for authenticated access, guest rejection, and unknown collections.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: abced4a6-96c3-4d26-abe7-91e965f9bcdb

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 97a9474 and e58d19e.

πŸ“’ Files selected for processing (5)
  • CHANGELOG.md
  • backend/resources/js/lib/realtimeCollection.js
  • backend/routes/api.php
  • backend/routes/web.php
  • backend/tests/Feature/Sync/CollectionSnapshotSessionAuthTest.php

πŸ“ Walkthrough

Walkthrough

The live-sync snapshot endpoint now uses web session authentication while retaining its URL and controller. Snapshot failures emit console warnings, and feature tests cover authenticated, unauthenticated, and unknown-collection responses.

Changes

Live-sync snapshot

Layer / File(s) Summary
Session-authenticated snapshot route
backend/routes/web.php, backend/routes/api.php, backend/tests/Feature/Sync/CollectionSnapshotSessionAuthTest.php
Moves GET /api/collections/{name} into the authenticated web route group and tests session access, guest rejection, and unknown collections.
Snapshot error diagnostics
backend/resources/js/lib/realtimeCollection.js, CHANGELOG.md
Logs a warning when snapshot loading fails and documents the route and error-reporting changes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • Mes-Open/OpenMes#124: Addresses authentication failures for the same live-sync snapshot endpoint through Sanctum host detection.

Suggested reviewers: svannte, jankolo04

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title clearly matches the main change: moving /api/collections to web-session auth to fix empty admin lists on some hosts.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/collections-session-auth-193

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant