feat(auth): token refresh retry on 401 responses#111
Open
feat(auth): token refresh retry on 401 responses#111
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds public tryRefreshToken() method that wraps the existing private refreshAccessToken() with token persistence and state updates, then returns the new access token string for use by the upcoming UnauthorizedInterceptor. Also configures jest-preset-angular for the web-auth-data-access library so Angular testing utilities work correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Spotify Web Playback SDK calls getOAuthToken multiple times (on expiry, reconnect, wake from sleep). Previously the callback captured a static token snapshot, so after a refresh the SDK kept using the stale token, causing authentication_error and NO_ACTIVE_DEVICE on play. Now reads the latest token from localStorage each time. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Moves the LOCALSTORAGE_KEYS constant from auth.store.ts (private) to local-storage.service.ts (exported) so both AuthStore and PlaybackService can reference keys without hardcoded strings or circular dependencies. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Per spotify/web-api#1325, passing device_id avoids 404 "No active device found" errors when Spotify loses track of the active device. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
PlayerApiService now stores the deviceId from transferUserPlayback() and automatically appends it as a query param on play() calls. Per spotify/web-api#1325, this avoids 404 "No active device found". Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
99f23a0 to
187a198
Compare
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
tryRefreshToken()public method toAuthStorethat refreshes the Spotify access token, persists new tokens to localStorage and store state, and returns the new access tokenUnauthorizedInterceptorto silently refresh expired tokens on 401 responses (up to 2 attempts) and replay the original failed request with the fresh tokenFlow
Test plan
AuthStore.tryRefreshToken()(success, localStorage persistence, state update, missing token error, API error propagation)UnauthorizedInterceptor(passthrough, non-401 errors, skip URLs, refresh+replay, 2 failures then modal, second attempt success, concurrent 401 coalescing, concurrent failure propagation)access_tokenfrom localStorage while app is running → verify silent refreshaccess_tokenandrefresh_token→ verify modal appears🤖 Generated with Claude Code