Skip to content

Session Sharing

📐 ADR: ADR-0004 — Session sharing between SFCC and Next.js (In Progress)

Users navigate between SFCC pages and Next.js MFEs on the same domain. Session state must be seamless — logged in on SFCC means logged in on Next.js pages.

Diagram

Because SFCC and MFEs are served from the same domain (via the CloudFront gateway), cookies set by SFCC are readable by Next.js and vice versa.

StateWhere It LivesHow MFEs Access
AuthenticationCookies on .hema.nl / .hema.comRead server-side (RSC) or via Web Shell
Cart contextSFCC Commerce APIWeb Shell api-client package
User identitySession cookieValidated per request
  1. Don’t implement your own auth — Use the Web Shell’s session handling (@hema/omni-web-app-shell-core)
  2. Cart operations go through Commerce API — Use @hema/omni-web-app-shell-api-client
  3. Cookies are httpOnly + secure — Can’t read auth cookies from client JS; use server-side
  4. Cookies flow through the gateway — CloudFront passes them to your origin during SSR
  5. Shell header handles UI state — Cart count, user name, login/logout are all managed by Web Shell
  • All auth cookies: httpOnly, secure, sameSite
  • Tokens validated on each request (not just trusted from cookie)
  • No sensitive data in client-accessible cookies