Fix WHOOP sync Cognito refresh and revoked token handling
Merged
AS
5mo ago+520+520+012345678901234567890123456789-243-243-012345678901234567890123456789
Summary
- Reuse stored WHOOP access tokens during sync when they are still valid, instead of calling Cognito refresh on every sync step.
- Treat Cognito
NotAuthorizedExceptionduring refresh as a revoked refresh token: delete stored tokens and surfaceRefreshTokenRevokedErrorso the UI prompts reconnect. - Add unit and integration coverage for token reuse, refresh failure, and revoked-token cleanup.
Test plan
-
pnpm vitest run src/providers/whoop.test.ts -
pnpm vitest run src/providers/whoop-sync.integration.test.ts
Made with Cursor
Summary by cubic
Reuse valid WHOOP Cognito access tokens and centralize token handling so sync stops refreshing on every step. Refresh failures now trigger a clean reconnect, WHOOP uses a custom-auth flow (no developer OAuth), and tokens are validated at the boundaries.
-
Bug Fixes
- Reuse stored access tokens when still valid; skip Cognito refresh and token writes.
- On Cognito NotAuthorizedException, delete stored tokens and surface RefreshTokenRevokedError so the app prompts WHOOP reconnect.
- Validate whoopAuth.saveTokens input; reject empty access/refresh tokens with clear errors.
- Zod-validate Cognito refresh payloads before persisting refreshed credentials.
-
Refactors
- Centralized WHOOP token logic in
resolveWhoopTokensandsaveWhoopAuthTokens; extracted WHOOP request logger. - Treated WHOOP as custom-auth: moved overrides to
src/lib/custom-auth-providers, usedproviderRequiresStoredTokensin the worker, passedCUSTOM_AUTH_PROVIDERStoProviderModel, and allowed custom-auth inprovider-auth-policy; removed the developer OAuth path and related env checks. - CI: Ignore
**/skills/stripe-projectssymlinks in Stryker and extend integration test timeout to 12 minutes.
- Centralized WHOOP token logic in
Summary by CodeRabbit
-
Bug Fixes
- Improved WHOOP authentication token refresh and error handling for better reliability during account sync.
- Enhanced token validation and storage logic for custom authentication providers.
-
Tests
- Added comprehensive test coverage for custom authentication provider handling and WHOOP token resolution workflows.