Overview
Manual Token Management
Simple approach where you handle token storage and refresh logic yourself
Automatic Token Management
Production-ready approach with automatic token refresh, persistence, and cleanup
Manual Token Management
Perfect for prototyping, testing, or when you need full control over token handling.Basic Setup
Authentication Flow
Manual Mode Methods
Automatic Token Management
Recommended for production applications. Handles token refresh, storage, and cleanup automatically.Token Storage Options
Browser localStorage Storage
- Basic Usage
- With Callbacks
- ✅ Persists across browser sessions
- ✅ Automatic token refresh
- ✅ Cross-tab synchronization
- ✅ Works with SPA frameworks (React, Vue, Angular)
Cookie Storage (SSR Compatible)
- Basic Setup
- Next.js Example
- ✅ SSR/SSG compatible
- ✅ Server and client access
- ✅ Cross-subdomain sharing
- ✅ Automatic expiry handling
Memory Storage (Server-Side)
- ✅ Fast in-memory access
- ✅ No persistence overhead
- ✅ Perfect for server environments
- ✅ Automatic cleanup on process end
Custom Token Storage
Implement theTokenStorage interface for custom storage solutions:
Authentication Patterns
Anonymous to Authenticated Flow
OTP Authentication Flow
Multi-Environment Token Management
Token Lifecycle Events
Handling Token Updates
JWT Utilities
The SDK provides utilities to extract information from tokens:Best Practices
✅ Production Recommendations
Security Best Practices
- Use secure cookies in production:
- Environment-specific configuration:
- Handle token events properly:
Framework Integration
For framework-specific token management patterns and implementation details, see our dedicated integration guides:React Integration
Context providers, hooks, and component patterns for React SPAs
Next.js Integration
SSR, Server Actions, and automatic cookie-backed token management
TanStack Start Integration
Server functions, route loaders, and pre-rendering
Astro Integration
SSR pages, API routes, middleware, and static prerendering
SvelteKit Integration
Server load functions, form actions, hooks, and universal loads
Node.js Integration
Server-side 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.