SDK middleware for authentication, token management, and debugging
The SDKβs middleware system provides automatic token management and request/response logging built on top of openapi-fetch. The middleware is internal to the SDK and handles authentication and debugging automatically.
Automatically handles token refresh and authentication for all requests when tokenStorage
is provided:
Features:
Request/response logging for development when debug mode is enabled:
Logged Information:
Request timeout handling when configured:
The SDKβs automatic token management requires a token storage implementation. For detailed information about all available token storage options, configuration, and best practices, see our comprehensive Token Management Guide.
The token storage you choose affects how the middleware handles authentication. See Token Management for complete storage options including BrowserTokenStorage, CookieTokenStorage, MemoryTokenStorage, and custom implementations.
The authentication middleware handles token management automatically:
Request Initiated
Client makes API request
Token Check
Middleware checks if access token exists and is valid
Token Refresh
If token is expired, automatically refreshes using refresh token
Storage Update
Updates token storage with new tokens
Request Completion
Original request proceeds with valid token
Without tokenStorage
, tokens must be managed manually:
For framework-specific token storage implementations and patterns:
Universal token storage for SSR/SSG applications
Browser-based storage with React context patterns
React to token changes with callback functions:
The middleware system is internal to the SDK and automatically configured based on your options. You cannot add custom middleware - the SDK handles authentication, debugging, and timeout management internally.