Skip to main content

Suggested Structure

The framework renders CMS pages through the catch all route app/(pages)/[...slug]. Static folders win over a catch all, so put the store in its own route group next to it.
A store route shadows a CMS page with the same slug. Do not create CMS pages called shop, cart, checkout or account.

Keep the Visitor’s Language on Store Pages

The framework’s proxy.ts sets the NEXT_LOCALE cookie from the first path segment, or to the default locale when there is none. Store pages have no locale prefix (/cart, /checkout/success, /account/verify-email), so the proxy would switch every visitor back to the default language. Change proxy.ts so it keeps the current cookie on store paths:
src/proxy.ts
To switch language on a store page, set the cookie and refresh. On a product page, also move to the product’s slug in the new language (the product answer carries slugs).
src/app/components/store-language-switcher.tsx
Crawlers have no cookie, so they always see store pages in the default language. If you need product pages indexed in several languages, add a locale segment to the store routes (for example /pt/shop/...) and pass that locale to the API instead of the cookie.

The API Client

This helper adds the token, the session headers and the client headers to every call, and turns error answers into a typed error. Install server-only (npm install server-only) so a client component can never import it by mistake.
src/lib/store/client.ts

Sessions and Cookies Helper

Next.js lets you write cookies only in Server Actions and Route Handlers. Server Components can only read them. So open sessions and drop dead tokens inside actions, and treat a 401 in a Server Component as “no session” for that render.
src/lib/store/session.ts
A small result type keeps Server Actions friendly to client components. Next.js hides the message of an error thrown by a Server Action in production, so return the error instead of throwing it.
src/lib/store/result.ts

Shared Types

src/lib/store/types.ts