Complete guide to authentication and token management in the TypeScript SDK
The CommerceEngine SDK provides two sophisticated approaches to token management, designed to handle everything from simple prototyping to production-scale applications with automatic token refresh and persistence.
Simple approach where you handle token storage and refresh logic yourself
Production-ready approach with automatic token refresh, persistence, and cleanup
Perfect for prototyping, testing, or when you need full control over token handling.
Get anonymous token
Login with credentials
Handle token refresh manually
Recommended for production applications. Handles token refresh, storage, and cleanup automatically.
Features:
Features:
Features:
Implement the TokenStorage
interface for custom storage solutions:
The SDK provides utilities to extract information from tokens:
Always use automatic token management in production with appropriate storage for your environment.
For framework-specific token management patterns and implementation details, see our dedicated integration guides:
Context providers, hooks, and component patterns for React applications
SSR-compatible patterns, API routes, and server-side token handling
Server-side implementation patterns and background job authentication
Token Management Summary: The SDKβs automatic token management handles all the complexity of authentication, token refresh, and storage, allowing you to focus on building your application features while ensuring a seamless user experience.