This guide covers the frontend only. Read the backend e-commerce guide to activate the
module and to set up products, markets, shipping methods, promotions, Stripe, email and customer accounts in the
admin panel.
How It Works
The storefront API works server to server only. Your Next.js server acts as the store’s BFF (backend for frontend): a small server layer that sits between the browser and Strapi. The browser talks only to your Next.js app. Your Next.js app talks to Strapi. Keep these rules in mind:- The browser never sees the API token and never calls Strapi. The storefront routes have no CORS setup on purpose. Do not add your storefront domain to
strapi::corsfor them. - Every request carries the API token in the
Authorizationheader. - Sessions live in cookies on your domain. Your Next.js server stores the session tokens in httpOnly cookies and forwards them to Strapi in headers.
- The server is the only source of truth for money. Strapi prices every cart and every order again from the catalog. It ignores any price, discount, total or stock value you send.
Base URL
All storefront routes live under:GET {API_BASE_URL}/api/littlebox-strapi-suite/ecommerce/storefront/products. The Stripe webhook route that Strapi handles by itself is POST {API_BASE_URL}/api/littlebox-strapi-suite/ecommerce/stripe/webhook.
Every route answers 404 Not Found while the e-commerce module is off, as if it did not exist. Strapi checks this before the API token, so even a request without a token gets 404.
Before You Start
Check the items below in the admin panel. The backend e-commerce guide explains each one.1
Activate the e-commerce module
Every storefront route answers
403 until the module is active.2
Generate the storefront API token
In the e-commerce module, open Settings → API and click Generate token. Copy the token right away: the
admin shows it only once. Click Regenerate to rotate it. The old token stops working at once, so deploy the
new one straight away.
3
Set the storefront URL
In Settings → General, fill in the storefront URL (for example
https://shop.example.com). Stripe return
URLs and every account email link use it. Without it, payment links answer 503 STOREFRONT_URL_MISSING and
account emails are not sent.4
Choose the markets and shipping methods
The store ships only to its markets (Settings → General). Each shipping method or carrier serves some of
them.
5
Set up Stripe and email
Configure Stripe (payments) and Resend (emails) in the module settings. Add the Stripe webhook in your Stripe
dashboard, pointing at the webhook route above.
6
Choose the customer accounts mode
In Settings → General → Customer accounts, choose guest only, registered only, or both. See
Customer accounts modes.
Environment Variables
Add one variable to the.env.local file of the framework:
.env.local
Request Headers
Your BFF builds every request header itself. Never copy a header that the browser sent.Bearer YOUR_STOREFRONT_API_TOKEN. Required on every route. A missing, wrong, expired or read only token gets
403.The guest checkout session token. Required on the cart, quote, discount, store credit, checkout email
verification and order routes when the visitor is not logged in. Optional on
POST /checkout/session. Also
required by register, verify email, login and reset password, which run on a guest session.The login session token (a JWT) of a logged in customer. Required on every private account route. When you send
it together with
X-Checkout-Session and it is valid, the login session wins. When it is invalid, expired or
revoked, Strapi answers 401 CUSTOMER_SESSION_INVALID and never falls back to the guest session.The IP address of the browser you serve: one IPv4 or IPv6 address. Strapi uses it for rate limits and stores it in
the customer activity log.
The browser’s
User-Agent. Strapi stores it (cut to 255 characters) on the customer’s login sessions and in the
customer activity log, so the store owner and the customer see which device did what.Required on
POST /orders. 8 to 100 characters from A-Z a-z 0-9 _ : -, one per checkout attempt. See
Idempotency keys.The Client IP and User Agent
The BFF must always overwriteX-Storefront-Client-IP and X-Storefront-Client-User-Agent with the real values of the browser it serves:
- Read the IP from the header your own infrastructure sets and trusts. On Vercel,
x-forwarded-forholds the client IP. Behind your own Nginx or load balancer, set a header such asX-Real-IPfrom the connection address and read that one. Never trust a value a browser can write. - Send a single address. Strapi treats a list, a zone id or any text as missing.
- Strapi never reads
X-Forwarded-Foror other proxy headers for its limits, because any client can forge them.
429 for every visitor. Strapi counts an IPv4 mapped IPv6 address (::ffff:203.0.113.7) as the IPv4 address, and any other IPv6 address by its /64 prefix.
Sessions and Cookies
The storefront API knows two kinds of sessions.Store the Tokens in Cookies
Keep both tokens in cookies that only your server reads:HttpOnly, so no script can read them.Secure, so they travel over HTTPS only.SameSite=LaxandPath=/.Expiresset to theexpiresAtthe API returns.
localStorage, in a client component prop or in a URL.
Open the Guest Session Lazily
Open the guest checkout session only when the visitor first needs one: when they add a product to the cart, start the checkout, or open a login, register or email link page. Never open one on every page view. Crawlers and one time visitors would each create a session row, and each new session counts against thesession.create limit (20 per hour per IP).
A few more rules:
- Call
POST /checkout/sessiononly when you have no cookie, or after the API answered401 SESSION_INVALID. - Strapi keeps only a hash of the token. It returns the token once. Store it right away.
- Strapi never tells apart a missing, malformed, unknown or expired session: all of them answer
401 SESSION_INVALID. Drop the cookie, open a new session and rebuild the cart. - An expired session is emptied when it is next used. Orders are never cancelled because a session expired.
Login Sessions
The login session token is a JWT (JSON Web Token): a signed string that identifies the session. Strapi never trusts it alone. On every request it checks the session row and the customer in the database, so a revoked session or a blocked customer stops working at once.- Login merges the carts. On login (and on email verification, which also logs the customer in), Strapi merges the guest cart into the account cart and retires the guest session. Drop the guest cookie after a login.
- The cart follows the customer. While logged in, the cart lives on the account, so it is the same on every device.
- Logout. Call
POST /account/logout, drop the customer cookie, and open a new guest session lazily when the visitor needs one. The cart stays on the account. - Stale tokens. Any route except the catalog answers
401 CUSTOMER_SESSION_INVALIDfor a dead login token. Drop the customer cookie and continue as a guest. - Password change.
POST /account/passwordreturns a new token. Replace the cookie with it, because the old token stops working.
Customer Accounts Modes
The store owner picks one mode in Settings → General → Customer accounts. The catalog works the same way in every mode.
Rules behind the table:
- You can always open a guest session, in every mode. In registered only mode, the guest session serves only the login, register and email link routes.
- A valid login session wins over a guest session.
- An invalid login token on any non catalog route answers
401 CUSTOMER_SESSION_INVALID. - In guest only mode, Strapi ignores
X-Customer-Tokenon every route except the account routes, which answer403 ACCOUNTS_DISABLED. - Payment link and order status stay open to guest sessions in every mode, so a guest can still pay an order placed before the owner switched to registered only.
- Accounts need the encryption key and the password pepper on the Strapi server. Without them, account routes answer
503 ACCOUNTS_UNAVAILABLE.
Money, Taxes, Locales and Images
- Money is integer cents in EUR, VAT included.
2500means €25.00. Every answer that carries money also carriescurrency: "EUR". Divide by 100 only to display. - Taxes. Variants carry
taxRate(a percentage such as23). Quotes carry ataxesbreakdown per rate:{ rate, base, vat, gross }, all in cents. - Locales. Catalog routes and cart bodies take a
localethat must be one of the Strapi locales. An empty value means the default locale. An unknown one answers400 invalid_locale. Texts fall back to the default locale when a translation is missing. - Images.
PublicImageis{ url, width, height, alt, cover }. With a cloud upload provider,urlis absolute. With Strapi’s local provider it is a relative/uploads/...path. The framework already rewrites/uploads/*to Strapi innext.config.ts, so these paths work as they are. Keep that rewrite: the store logo in emails also points at{storefrontUrl}/uploads/.... - Galleries. Images come in the order the admin set. Exactly one image of a gallery has
cover: true. Show the gallery in the given order and use the cover for thumbnails.
src/lib/store/money.ts