From storefront-next
Implement authentication in Storefront Next using split-cookie architecture, SLAS tokens, and auth middleware. Use when accessing user identity in loaders, detecting guest vs registered users, using getAuth or useAuth, or understanding session management and token refresh.
How this skill is triggered — by the user, by Claude, or both
Slash command
/storefront-next:sfnext-authenticationThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
This skill covers Storefront Next's split-cookie authentication architecture with SLAS (Shopper Login and API Access Service).
This skill covers Storefront Next's split-cookie authentication architecture with SLAS (Shopper Login and API Access Service).
Storefront Next uses a split-cookie architecture separating server and client auth concerns:
auth.server.ts) — Manages SLAS tokens, writes cookies, handles token refreshAuthProvider) — Provides public session data (non-sensitive fields) to components via useAuth()| Cookie | Purpose | User Type | Expiry | HttpOnly |
|---|---|---|---|---|
cc-nx-g | Guest refresh token | Guest | 30 days | No |
cc-nx | Registered refresh token | Registered | 90 days | No |
cc-at | Access token | Both | 30 min | No |
usid | User session ID | Both | Matches refresh | No |
customerId | Customer ID | Registered | Matches refresh | No |
Key points:
siteIdimport { getAuth } from '@/middlewares/auth.server';
export function loader({ context }: LoaderFunctionArgs) {
const auth = getAuth(context);
const { accessToken, customerId, userType } = auth;
const isGuest = userType === 'guest';
const isRegistered = userType === 'registered';
return { isGuest, customerId };
}
import { useAuth } from '@/providers/auth';
export function MyComponent() {
const auth = useAuth();
if (auth?.userType === 'guest') {
return <LoginPrompt />;
}
return <div>Welcome, customer {auth?.customerId}</div>;
}
export function loader({ context }: LoaderFunctionArgs) {
const auth = getAuth(context);
if (auth.userType === 'guest') {
throw redirect('/login');
}
const clients = createApiClients(context);
return {
orders: clients.shopperOrders.getOrders({
params: { path: { customerId: auth.customerId } }
}).then(({ data }) => data),
};
}
export function loader({ context }: LoaderFunctionArgs) {
const auth = getAuth(context);
const clients = createApiClients(context);
const base = {
products: clients.shopperProducts.getProducts({...}).then(({ data }) => data),
};
if (auth.userType === 'registered') {
return {
...base,
wishlist: clients.shopperCustomers.getWishlist({...}).then(({ data }) => data),
};
}
return base;
}
| Issue | Cause | Solution |
|---|---|---|
auth is undefined | Missing auth middleware | Ensure auth.server.ts middleware is configured |
| Always guest | Refresh token expired | Check cookie expiry; SLAS auto-refreshes |
| Token errors in SCAPI | Stale access token | Tokens auto-refresh; check SLAS client configuration |
storefront-next:sfnext-data-fetching - Using auth context in loader functionsstorefront-next:sfnext-configuration - SLAS client configurationstorefront-next:sfnext-hybrid-storefronts - Session bridging with SFRAnpx claudepluginhub salesforcecommercecloud/b2c-developer-tooling --plugin storefront-nextGuides completion of development work by verifying tests, detecting environment, and presenting structured options for merge, PR, or cleanup.
Enforces test-driven development: write failing test first, then minimal code to pass. Use when implementing features or bugfixes.
Guides creation and editing of skills using test-driven development with pressure scenarios and subagents to verify agent compliance.