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.
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.
import { BrowserTokenStorage } from '@commercengine/storefront-sdk';const client = new StorefrontSDK({ storeId: 'your-store-id', apiKey: 'your-api-key', tokenStorage: new BrowserTokenStorage('my_app_')});
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 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.