Skip to content

fix(android): keep live sync working in the native app - #296

Merged
arogan178 merged 2 commits into
masterfrom
fix/android-live-sync
Oct 21, 2026
Merged

arogan178 merged 2 commits into
masterfrom
fix/android-live-sync

Conversation

@arogan178

Copy link
Copy Markdown
Owner

Why

Live sync never worked in the Android app. /api/sync/events returned 401 on every connect, so changes made on another device only showed up after a refetch.

EventSource cannot send an Authorization header. On the web, Clerk's cookie authenticates the stream. The native app runs at app.macrotrackr.com, so that cookie never reaches macrotrackr.com.

What changes

  • The app always trades its session token for a one-time sync ticket before opening the stream. Local sessions already did this; Clerk sessions now do too.
  • When Clerk's own check finds no session on /api/sync/events, the Clerk middleware redeems the ticket and verifies the token inside it with Clerk, using the same authorized parties as every other request.
  • The ticket rules don't change: single use, 30 seconds, only on the sync stream.

On the web the cookie still authenticates the stream first, so the ticket goes unused there and expires.

Testing

  • New tests for the ticket check: the token reaches Clerk as a Bearer header, the ticket is burned after one connect, it is ignored on any other endpoint, and a token Clerk refuses gets no user.
  • Backend 503/503, frontend 1294/1294. Typecheck and lint clean apart from warnings that were already there.
  • Device test on the Pixel 8 Pro after deploy is still to do.

EventSource cannot send an Authorization header, and the native app's
Clerk cookie never reaches the API, so the sync stream returned 401 and
the app only caught up on refetch. Clerk sessions now trade their token
for the same one-time sync ticket local sessions use, and the Clerk
middleware verifies the redeemed token with Clerk.
Clerk's authenticateRequest asserts the publishable key, and the
decorated client only gets it from process.env.
@arogan178
arogan178 merged commit cb6917f into master Oct 21, 2026
7 checks passed
@arogan178
arogan178 deleted the fix/android-live-sync branch October 21, 2026 09:55
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