From storefront-next
Implements Storefront Next authentication using split-cookie architecture, SLAS tokens, and auth middleware. Use for user identity in loaders, guest vs registered detection, getAuth/useAuth, and session management.
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-nextImplements complete Next.js authentication with Auth.js: OAuth providers (GitHub/Google), credentials login, Prisma adapter, session management (JWT/DB), middleware-protected routes, RBAC, and login forms.
Implements advanced Next.js patterns with Clerk: middleware strategies, Server Actions protection, API route auth (401 vs 403), and user-scoped auth caching.
Manages client-side state in Storefront Next using React context providers and Zustand stores for basket/auth UI state, extension stores, and post-mutation sync.