Skip to content

fix(sportySync): add User-Agent to Supabase write requests#268

Merged
ChristopherRotnes merged 3 commits into
masterfrom
fix/sporty-sync-user-agent
Jun 19, 2026
Merged

fix(sportySync): add User-Agent to Supabase write requests#268
ChristopherRotnes merged 3 commits into
masterfrom
fix/sporty-sync-user-agent

Conversation

@ChristopherRotnes

Copy link
Copy Markdown
Owner

Summary

  • Supabase rejects POST/DELETE with sb_secret service role key when no User-Agent header is present — treats the request as a browser call and returns 403
  • Azure Functions native fetch sends no User-Agent by default, so cleanup DELETE and upsert POST in sportySync.js have been silently failing since deployment
  • Each sync run: cleanup wiped future gym_calendar rows, then the upsert failed to re-insert them → table empty from June 6 onwards (3+ weeks of missing gym class data)
  • GET requests (health check) still worked, masking the failure
  • Added User-Agent: WorkoutLens/1.0 sporty-sync (Azure Functions) to both write requests

Test plan

  • Merge and wait for Azure SWA deploy to complete
  • Trigger manual backfill via DEV button or POST /api/sporty-sync {"daysBack": 14} to restore June 6+ data
  • Verify via GET /api/sporty-health that gym_calendar has data for the next 7+ days
  • Confirm gym class dropdown appears in the session logger for upcoming days

🤖 Generated with Claude Code

ChristopherRotnes and others added 3 commits May 27, 2026 22:36
…e sessions

Sporty's API ignores period_start and always returns sessions from tomorrow
onwards, so same-day sessions could only ever be captured the night before.
Adding a 22:00 UTC timer run (midnight Oslo CEST) ensures next-day sessions
are captured while Sporty still treats them as "tomorrow".

The sync now also deletes future gym_calendar rows within the sync window
before each upsert, removing cancelled/rescheduled sessions that Sporty
has dropped. The cleanup only runs when Sporty returns data (guards against
API outages) and never touches rows before the next Oslo midnight (preserves
same-day sessions from the 22:00 UTC run across later runs in the same day).
Backfill runs (shiftDays != 0) skip the cleanup entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Supabase rejects POST/DELETE with sb_secret service role key when
no User-Agent is present — treats the request as a browser call.
Azure Functions native fetch sends no User-Agent by default, so
the cleanup DELETE and upsert POST were silently failing after each
sync run. The cleanup wiped future gym_calendar rows; the upsert
then failed to re-insert them, leaving gym_calendar empty from
June 6 onwards while GET requests (health check) still worked.

Added User-Agent header to both write requests. Post-deploy a
manual backfill sync is needed to restore June 6+ data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Azure Static Web Apps: Your stage site is ready! Visit it here: https://white-island-090dfd003-268.westeurope.7.azurestaticapps.net

@ChristopherRotnes ChristopherRotnes merged commit 66beca4 into master Jun 19, 2026
2 checks passed
@ChristopherRotnes ChristopherRotnes deleted the fix/sporty-sync-user-agent branch June 19, 2026 21:49
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