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/) — call@spree/sdkdirectly with auth/cookie helpers fromsrc/lib/spree - 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 via
getLocaleOptions()
Project Structure
Authentication Flow
- User submits login form
- Server action calls
@spree/sdkto authenticate - JWT token is stored in an httpOnly cookie via
src/lib/spreecookie helpers - Subsequent requests use
withAuthRefresh()which reads the token from cookies 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 src/lib/spree 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 call @spree/sdk directly, using src/lib/spree helpers for auth and locale:

