/storefront-next:sfnext-authenticationfrom storefront-next
Work with Storefront Next's server-only authentication and session architecture: SLAS guest/registered tokens, httpOnly cookies, auth.server.ts middleware, getAuth/useAuth/updateAuth/destroyAuth, account route protection, login/logout actions, guest-to-registered basket/wishlist merge, session-expired redirects, 401 recovery loops, cookie…
Ships in storefront-next. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Authentication is server-only. One middleware (src/middlewares/auth.server.ts, registered in the middleware array of src/root.tsx) runs on every request: it reads cookies, validates or refreshes the SLAS access token, performs a guest login when nothing usable exists, and writes Set-Cookie. Tokens never reach the browser. Components only see a small non-sensitive slice through useAuth().
Read docs/README-AUTH.md in your project for the full reference; this skill is the task-oriented summary. Route modules use server loader/action only, never clientLoader/clientAction.
exp in the future): use it.cc-at./login?returnUrl=<path>&error=session_expired (site/locale prefix included) and a fresh guest session is created in parallel. Guests are silently re-issued a guest session.AuthTokenInvalidError; the middleware clears state, re-runs login/refresh and 307-redirects to the same URL. The short-lived cc-auth-recover cookie (30 s) prevents loops.User type comes from the access-token JWT (registered tokens carry an rcid claim), not from which cookie exists. customerId is not a cookie; it is derived per request from the JWT.
import { getAuth } from '@/middlewares/auth.server';
import type { LoaderFunctionArgs } from 'react-router';
export async function loader({ context }: LoaderFunctionArgs) {
const auth = getAuth(context); // full SessionData, server only
const isRegistered = auth.userType === 'registered';
return { isRegistered }; // never return auth.accessToken / refreshToken
}
import { useAuth } from '@/providers/auth';
function AccountBadge() {
const auth = useAuth(); // PublicSessionData | undefined
return auth?.userType === 'registered' ? <span>Welcome back</span> : <SignInLink />;
}
PublicSessionData is exactly customerId, userType, usid, encUserId, trackingConsent. The root loader derives it with getPublicSessionData (from @/middlewares/auth.utils) and passes it to AuthProvider; there is no client getAuth.
Branch inside the server loader. Prefer the existing account layout (src/routes/_app.account.tsx) for anything under /account instead of adding per-route checks.
import { redirect } from 'react-router';
import { getAuth } from '@/middlewares/auth.server';
import { buildUrlFromContext } from '@/lib/url.server';
import { routes } from '@/route-paths';
export async function loader({ context }: LoaderFunctionArgs) {
if (getAuth(context).userType !== 'registered') {
throw redirect(buildUrlFromContext(routes.login, context)); // keeps site/locale prefix
}
// ...
}
Never write auth cookies yourself. Use the helpers exported from @/middlewares/auth.server:
import { loginRegisteredUser, updateAuth } from '@/middlewares/auth.server';
export async function action({ request, context }: ActionFunctionArgs) {
const form = await request.formData();
const tokens = await loginRegisteredUser(context, String(form.get('email')), String(form.get('password')));
updateAuth(context, tokens); // re-derives userType/customerId/usid, swaps cc-nx-g for cc-nx
return redirect('/account');
}
updateAuth accepts a SLAS token response or an updater function (updateAuth(context, (cur) => ({ ...cur, codeVerifier }))). Logout: destroyAuth(context) clears every auth cookie on the response; the shipped src/routes/_empty.logout.ts also calls clients.auth.logout and destroyBasket. Prefer src/lib/api/auth/standard-login.server.ts and social-login.server.ts over hand-rolled flows: they already handle the merge below.
Other exported helpers: loginGuestUser, refreshAccessToken, authorizePasswordless, getPasswordLessAccessToken, getPasswordResetToken, resetPasswordWithToken, requestOtp, verifyOtp, flashAuth(context, message) (clear session plus an error message), clearInvalidSessionAndRestoreGuest(context) (deleted customer or corrupted session).
customerId changes from the guest gcid to the registered rcid at the token swap, and SCAPI rejects the guest id under the registered token. So: snapshot guest-owned data (wishlist) before the swap, then mergeBasket and mergeWishlist after. src/lib/api/auth/social-login.server.ts is the reference implementation. dw_dnt tracking consent is preserved across the swap.
These are real operations: clients.shopperCustomers.getCustomerOrders, getCustomerProductLists (wishlists), getCustomer. Use the existing helpers (src/lib/api/order.server.ts, wishlist.server.ts, customer.server.ts) rather than calling clients directly. Client setup and the @/lib/api-clients.server import are covered in storefront-next:sfnext-scapi.
| Setting | Where |
|---|---|
| Refresh-token lifetime | PUBLIC_COMMERCE_API_GUEST_REFRESH_TOKEN_EXPIRY_SECONDS (max 30 days), PUBLIC_COMMERCE_API_REGISTERED_REFRESH_TOKEN_EXPIRY_SECONDS (max 90 days) |
| Feature flags | features.passwordlessLogin, features.passkey, features.socialLogin, features.otpRequest, auth.otpLength in config.server.ts |
| Private SLAS client | commerce.api.privateKeyEnabled (required for passwordless / OTP) |
| Cookie domain | app.cookies.domain (see storefront-next:sfnext-security) |
secure on cookies is only set on deployed (HTTPS) environments; local pnpm dev over http://localhost writes non-secure cookies so Safari keeps them.
document.cookie: impossible by design (httpOnly). Use useAuth() or loader data.getAuth(context) from a loader leaks tokens into the page. Return only derived values.accessToken or refreshToken: never./login?error=session_expired usually means refresh tokens are being rejected (SLAS client config, or cookie domain mismatch between hosts).docs/README-AUTH.md, docs/README-EMAIL-VERIFICATION.md, docs/README-GUEST-ORDER-LOOKUP.md, docs/README-EMAIL-CARTRIDGE.md.storefront-next:sfnext-security - Turnstile bot protection, CSP for social providers, cookie domainstorefront-next:sfnext-scapi - SCAPI clients and custom APIsstorefront-next:sfnext-hybrid-storefronts - shared dwsid session bridge with SFRAstorefront-next:sfnext-analytics-consent - dw_dnt tracking consentstorefront-next:sfnext-configuration - config.server.ts and PUBLIC__ overridesb2c-cli:b2c-slas - manage SLAS clients and scopesWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub salesforcecommercecloud/b2c-developer-tooling --plugin storefront-next25 skills in this plugin
/sfnext-accessibilityBuild and fix accessible UI in a Storefront Next storefront (WCAG 2.1 AA): jsx-a11y lint findings, missing accessible names and labels, form error association, dialog focus management, aria-live status messages, keyboard behavior, color contrast, and verifying fixes with Storybook a11y/play() tests and the e2e axe scan with its baseline. Use for "accessibility", "a11y", "WCAG", "screen reader", "aria-label", "focus trap", "axe violation", pnpm lint:a11y, pnpm a11y, a11y-baseline.json, skip-a11y, STORYBOOK_A11Y_TEST_MODE, or an accessibility audit finding to fix. Do not use for general lint/typecheck gates (use `storefront-next:sfnext-quality-gates`), writing non-accessibility tests (use `storefront-next:sfnext-testing`), or color/token design (use `storefront-next:sfnext-theming`)./sfnext-analytics-consentStorefront Next analytics: engagement adapters (Einstein, Active Data, Data 360), adding a custom adapter, tracking consent gating, PageViewTracker, useAnalytics events, and first-touch attribution (dw_attribution). Use when configuring engagement.adapters in config.server.ts, writing an adapter with hasConsent, registering it in initializeEngagementAdapters, wiring the consent banner (trackingConsent, consentCategories, dw_dnt), firing trackViewProduct/trackCartItemAdd events, debugging why no analytics events are sent, or passing campaign attribution to orders. Do not use for general config loading or env vars (use `storefront-next:sfnext-configuration`), CSP/script allowlisting of third-party tags (use `storefront-next:sfnext-security`), or SEO meta/JSON-LD (use `storefront-next:sfnext-seo`)./sfnext-commerce-featuresCatalogue and router for optional Storefront Next commerce features: Shopper Context (qualifiers, source codes), Order Management returns/cancel/tracking (SOM/OMS), delivery estimates, feature stubs (@feature-stub), guest order lookup, the app_storefrontnext_base email cartridge, and the shipped extensions (bnpl, bopis, multiship, store-locator, ratings-reviews, customer-preferences, product-content, shipping-delivery, theme-switcher). For each: which flag, SLAS scope, Business Manager setting, cartridge, or extension registry entry it needs, and which in-project doc to read. Use when asked how to enable a feature, why a feature does not render, what prerequisites a feature has, or which stubs are mock data. Do not use for building a new extension (use `storefront-next:sfnext-extensions`), config loading (use `storefront-next:sfnext-configuration`), or SLAS login flows (use `storefront-next:sfnext-authentication`)./sfnext-componentsBuild and modify UI components in a Storefront Next storefront: page components with Suspense and use()/Await, createPage and withSuspense, Tailwind v4 token classes, shape tokens (rounded-ui, shadow-ui, border-ui), shadcn/ui primitives in src/components/ui (sync-shadcn), CVA variants, data-slot, DynamicImage, lazy-loaded overlays, and Storybook stories with snapshot tests. Use when creating or editing a component in src/components, adding a shadcn primitive, fixing styling that ignores the theme, writing a *.stories.tsx file, or running pnpm storybook:test. Do not use for re-branding colors, fonts, or logos (use `storefront-next:sfnext-theming`), route loaders (use `storefront-next:sfnext-data-fetching`), or Page Designer registration (use `storefront-next:sfnext-page-designer`)./sfnext-configurationConfigure a Storefront Next app: config.server.ts (defineConfig, metadata/runtime/app), AppConfig types in src/types/config.ts, PUBLIC__ environment variable overrides, getConfig(context) / useConfig(), extension config (app.extension, app.serverExtension), protected paths, server-only secrets, and multi-site settings (commerce.sites, url.prefix, seoRoutes, siteAliasMap, cookie domain). Use when editing config.server.ts, adding a config value, an env var is ignored or "not applied", `pnpm config:inspect` / `config:push-env`, "Ignoring environment variable" warnings, protected config path errors, setting up a second site or locale URLs, or going through the pre-launch config checklist. Do not use for creating a project or the npm script list (use `storefront-next:sfnext-project-setup`), pushing bundles or MRT env management (use `storefront-next:sfnext-deployment` / `b2c-cli:b2c-mrt`), or hybrid proxy and cookie-sharing with SFRA (use `storefront-next:sfnext-hybrid-storefronts`)./sfnext-data-fetchingLoad and mutate data in a Storefront Next project: route loaders that call SCAPI through createApiClients from @/lib/api-clients.server, critical versus streamed (deferred) data, createBasketAction and BasketAction for cart actions, createActionError and ErrorCode, data() responses, useFetcher and the useScapiFetcher hook with its server allowlist, request-scoped dedupe and MRT timeouts, non-personalized SCAPI responses, shopper context, and custom API clients. Use for "fetch products in a loader", "stream data", "add a cart action", "call SCAPI from a component", "resource route", "NormalizedApiError", or "loader blocks the page". Do not use for route files or links (use `storefront-next:sfnext-routing`), when loaders re-run after actions (use `storefront-next:sfnext-revalidation`), Suspense/LCP tuning (use `storefront-next:sfnext-performance`), or defining SCAPI custom APIs (use `storefront-next:sfnext-scapi`).Other plugins' skills for the same job