Spotify API Token Management Service

This module provides comprehensive management of Spotify API authentication tokens, handling all aspects of token lifecycle including storage, validation, retrieval, and automatic refresh of expired tokens.

Features:

  • Secure in-memory token storage
  • Token validation and expiry checking
  • Access token auto-refresh using refresh tokens
  • Token information retrieval
  • Token state management
  • Intelligent token refresh scheduling
  • Comprehensive error handling for token operations

This module works closely with the Authentication module to maintain a valid authentication state throughout the application's lifecycle.

Usage:

import {
ensureValidToken,
getAccessToken,
refreshAccessToken
} from '@/services/spotify/token';

// Before making API calls, ensure a valid token
await ensureValidToken();

// Get the current token for API requests
const token = getAccessToken();

// Manual token refresh if needed
await refreshAccessToken();

Functions

isTokenValid
setTokens
clearTokens
getTokenInfo
getAccessToken
getRefreshToken
refreshAccessToken
ensureValidToken