Skip to main content
This guide shows you how to build a full online store on top of the e-commerce module of the Littlebox Strapi Suite plugin, using the Littlebox Strapi Frontend framework (Next.js App Router). It covers the catalog, the cart, shipping, promotions, checkout, Stripe payments and customer accounts, and it documents every endpoint of the storefront API.
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.
Every code sample in this guide is an example. None of it is part of the framework core. Copy it, adapt it to your project, and review it before you go live.

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::cors for them.
  • Every request carries the API token in the Authorization header.
  • 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:
For example, the product list is 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
The framework’s API_TOKEN is a read only token for pages, menus and translations. The storefront API refuses it with 403. Only the token generated in the e-commerce settings passes. Never prefix the storefront token with NEXT_PUBLIC_: that would ship it to the browser.

Request Headers

Your BFF builds every request header itself. Never copy a header that the browser sent.
string
required
Bearer YOUR_STOREFRONT_API_TOKEN. Required on every route. A missing, wrong, expired or read only token gets 403.
string
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.
string
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.
string
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.
string
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.
string
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 overwrite X-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-for holds the client IP. Behind your own Nginx or load balancer, set a header such as X-Real-IP from 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-For or other proxy headers for its limits, because any client can forge them.
When the header is missing or invalid, Strapi applies only the per session and per email limits. A few rules (opening a session, register, login, resend, forgot password and the email link routes) then count in one shared bucket for the whole store, so a BFF that forgets the header soon gets 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.
Leave both client headers out only on catalog requests that Next.js caches (build time or ISR). There is no browser behind those requests, and the catalog limit simply does not apply without an IP.

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=Lax and Path=/.
  • Expires set to the expiresAt the API returns.
Never put a token in localStorage, in a client component prop or in a URL.
Protect against CSRF. SameSite=Lax alone is not enough. Next.js Server Actions compare the Origin header with the host for you. If you write Route Handlers that change data (cart, codes, orders, account), check the Origin header or an anti CSRF token yourself.

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 the session.create limit (20 per hour per IP). A few more rules:
  • Call POST /checkout/session only when you have no cookie, or after the API answered 401 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_INVALID for a dead login token. Drop the customer cookie and continue as a guest.
  • Password change. POST /account/password returns 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-Token on every route except the account routes, which answer 403 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.
The API has no endpoint that tells you the current mode. Mirror it in an environment variable (for example STORE_ACCOUNTS_MODE=BOTH) to show or hide the login links, and still handle ACCOUNTS_DISABLED and LOGIN_REQUIRED in case the owner changes it.

Money, Taxes, Locales and Images

  • Money is integer cents in EUR, VAT included. 2500 means €25.00. Every answer that carries money also carries currency: "EUR". Divide by 100 only to display.
  • Taxes. Variants carry taxRate (a percentage such as 23). Quotes carry a taxes breakdown per rate: { rate, base, vat, gross }, all in cents.
  • Locales. Catalog routes and cart bodies take a locale that must be one of the Strapi locales. An empty value means the default locale. An unknown one answers 400 invalid_locale. Texts fall back to the default locale when a translation is missing.
  • Images. PublicImage is { url, width, height, alt, cover }. With a cloud upload provider, url is absolute. With Strapi’s local provider it is a relative /uploads/... path. The framework already rewrites /uploads/* to Strapi in next.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