fix(sportySync): add User-Agent to Supabase write requests#268
Merged
Conversation
…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>
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://white-island-090dfd003-268.westeurope.7.azurestaticapps.net |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sb_secretservice role key when noUser-Agentheader is present — treats the request as a browser call and returns 403fetchsends no User-Agent by default, so cleanup DELETE and upsert POST insportySync.jshave been silently failing since deploymentgym_calendarrows, then the upsert failed to re-insert them → table empty from June 6 onwards (3+ weeks of missing gym class data)User-Agent: WorkoutLens/1.0 sporty-sync (Azure Functions)to both write requestsTest plan
POST /api/sporty-sync {"daysBack": 14}to restore June 6+ dataGET /api/sporty-healththatgym_calendarhas data for the next 7+ days🤖 Generated with Claude Code