Server-First Pattern
The storefront follows a server-first architecture where all API calls are made server-side. The Spree API key is never exposed to the browser.- Server Actions (
src/lib/data/) — thin wrappers around@spree/nextdata functions - httpOnly Cookies — auth tokens, cart tokens, and locale are stored securely
- No Client-Side API Calls — the Spree API key stays on the server
- Auto-Localization — locale and country are read from cookies automatically by
@spree/next
Project Structure
Authentication Flow
- User submits login form
- Server action calls
@spree/nextwhich authenticates with the Spree API - JWT token is stored in an httpOnly cookie by
@spree/next - Subsequent requests include the token automatically
- Token is never accessible to client-side JavaScript
Multi-Region Support
The storefront supports multiple countries and currencies via URL segments:src/proxy.ts) uses createSpreeMiddleware from @spree/next to detect the visitor’s country and locale, then redirects to the correct URL prefix. The CountrySwitcher component lets users change regions manually.
Server Actions
All data fetching is done through server actions insrc/lib/data/. These are thin wrappers around @spree/next functions — locale and currency are resolved automatically from cookies:

