hydrogen-customer-account
Skill218 starsChanged 4 days agoMITView on GitHub
Customer Account API setup for Hydrogen storefronts. Use when wiring customer sessions, login/logout/OAuth route handlers, account profile, order history, account-gated UI, cart buyer identity sync, or Customer Account GraphQL queries.
1 other project uses a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- Shopify/hydrogenedited, first seen Oct 13, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- Shopify/hydrogen★ 2.2k100% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository23 other files it gives its agents.
- AGENTS.mdAGENTS.md
- hydrogen-analyticsSkill
- hydrogen-cart-drawerSkill
- hydrogen-cart-metafieldsSkill
- hydrogen-cart-uiSkill
- hydrogen-collection-browserSkill
- hydrogen-imageSkill
- hydrogen-local-httpsSkill
- hydrogen-marketsSkill
- hydrogen-moneySkill
- hydrogen-oxygenSkill
- hydrogen-predictive-searchSkill
- hydrogen-request-handlersSkill
- hydrogen-robots-txtSkill
- hydrogen-routingSkill
- hydrogen-setupSkill
- hydrogen-shop-paySkill
- hydrogen-smoke-testSkill
- hydrogen-storefront-clientSkill
- hydrogen-variant-formSkill
- migrate-to-hydrogen-2026-10Skill
- remix-storeSkill
- testing-practicesSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 3 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 20
Use server-side configuration for:
- Distinctive: line 26
Do not expose access tokens, refresh tokens, ID tokens, or session secrets to client components or browser storage.
- Very specific: line 30
Create customerSession at module scope with createCustomerSession({ shopId, customerAccountApiClientId }).
- Very specific: line 32
Use the same requestContext for Storefront and Customer Account work in a request.
- Very specific: line 36
Read-only helpers return or accept ReadonlyCustomerSessionManager.
- Very specific: line 78
Do not reimplement login, authorize, refresh, or logout unless the app needs custom behavior that preserves the same safeguards: return_to …
- Very specific: line 84
Use customerSession.isLoggedIn() for read-only signed-in UI such as an account link.
- Very specific: line 85
Use customerSession.getAccessToken() before Customer Account GraphQL calls.
- Very specific: line 86
If isLoggedIn() is true but getAccessToken() returns undefined, redirect once to /account/refresh?return_to=...
- Very specific: line 87
If isLoggedIn() is false, show login UI or redirect to /account/login instead of sending the user to /account/refresh.
- Distinctive: line 101
Never serialize tokens or session objects into loader data or HTML.
- Very specific: line 105
Use gql and createCustomerAccountClient from @shopify/hydrogen/customer-account in server code only.
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Customer Account API
The Customer Account API powers login, account profile, order history, and account-gated UI. Hydrogen provides typed GraphQL helpers and OAuth/session primitives; the app still owns framework integration, UI, and session storage.
Configuration
Use server-side configuration for:
SHOP_ID— numeric Shopify shop ID string. Do not use a Shop GID or shop domain.PUBLIC_CUSTOMER_ACCOUNT_API_CLIENT_ID— Customer Account API client ID.CUSTOMER_ACCOUNT_SESSION_SECRET— private per-app secret for encrypted cookie examples, or replace cookie storage with opaque server-side sessions in production.
Do not expose access tokens, refresh tokens, ID tokens, or session secrets to client components or browser storage.
Session Module
Create customerSession at module scope with createCustomerSession({ shopId, customerAccountApiClientId }). Create request-scoped session managers from the framework request, backed by protected server storage or encrypted HttpOnly cookies.
Use the same requestContext for Storefront and Customer Account work in a request. Customer Account reads and GraphQL calls mark responses personalized so final response headers must run through requestContext.applyResponseHeaders().
Expose two app-owned session-manager helpers when the framework has both read-only render paths and writable response boundaries:
- Read-only helpers return or accept
ReadonlyCustomerSessionManager. Use them in Server Components, layouts, loaders, and account header UI. - Writable helpers return or accept
WritableCustomerSessionManager. Use them only where the returned response can commitSet-Cookie, such as Hydrogen route handlers, route handlers, server functions, middleware/proxy responses, or framework finalizers.
This makes the dangerous path harder to hold wrong: TypeScript rejects customerSession.getOrRefreshAccessToken() when the caller only has a ReadonlyCustomerSessionManager.
Route Wiring
Register createCustomerAccountServerHandlers({ customerSession }) with the app's handleShopifyRoutes setup.
Cart Buyer Identity Sync
To keep the browser cart's buyer identity in step with the customer session, create the cart handlers with the same customerSession and pass them to the Customer Account handlers:
import { createCartServerHandlers } from "@shopify/hydrogen";
import { createCustomerAccountServerHandlers } from "@shopify/hydrogen/customer-account";
const cartHandlers = createCartServerHandlers({ customerSession });
const customerAccountHandlers = createCustomerAccountServerHandlers({
customerSession,
cartServerHandlers: cartHandlers,
});With this wiring, Hydrogen owns the whole loop:
- New carts are created with the current customer's buyer identity when the session has a usable access token or successfully refreshed access token, and authenticated cart reads mark checkout URLs with
logged_in=true(from the cart handlers'customerSessionoption). - Authorization and refresh attach the customer to the cart from the request's cart cookie; a definitive refresh rejection detaches it. Transient refresh failures leave the cart untouched.
- Logout detaches the customer from the cart.
Sync is best-effort: a failed cart mutation never blocks the route's redirect. Attach failures are logged and can be retried by a later refresh. If detach fails during logout or definitive refresh rejection, the handler expires the cart cookie so a shared device never keeps a cart bound to the previous customer.
cartServerHandlers requires both handler groups to share the customerSession returned by createCustomerSession; TypeScript rejects cart handlers created without customerSession.
The Customer Account handlers own:
GET /account/loginGET /account/authorizeGET /account/refreshPOST /account/logout
Do not reimplement login, authorize, refresh, or logout unless the app needs custom behavior that preserves the same safeguards: return_to limited to the same origin, same-origin logout POST checks, cache-control: no-store, committed session cookies on the returned response, and request-context response headers.
Server Rendering
Server-rendered account UI must keep session reads and token refresh separate:
- Use
customerSession.isLoggedIn()for read-only signed-in UI such as an account link. It treats a refreshable session as logged in without refreshing tokens. - Use
customerSession.getAccessToken()before Customer Account GraphQL calls. It returns only a currently usable access token. - If
isLoggedIn()is true butgetAccessToken()returnsundefined, redirect once to/account/refresh?return_to=...from a dynamic server route, then retry the account page after the refresh route commits cookies. - If
isLoggedIn()is false, show login UI or redirect to/account/logininstead of sending the user to/account/refresh. - Include a one-shot refresh guard in the
return_topath, such as/account?refreshed=1; if the refreshed page still has no usable access token, fall back to login or an account error state. - Server Components and layouts should only receive
ReadonlyCustomerSessionManager, so they cannot callgetOrRefreshAccessToken().
Wrap header/account-link UI in the framework's streaming primitive when possible so the shell can render before session state resolves.
Account Page
Hydrogen ships no account UI yet — the app owns it. A storefront with the handlers wired but no account page has working auth endpoints a buyer can never reach. Build at least a minimal /account route:
- Signed out — render a sign-in panel linking to
/account/login?return_to=/account. The login link must be a full-document navigation (plain<a>or the framework link's reload-document mode): the handler returns a raw redirect to Shopify's hosted login page that client-side routing cannot follow. - Signed in — fetch and render a minimal profile (
customer { firstName lastName emailAddress { emailAddress } }). Check GraphQLerrorsand render an error state instead of crashing. - Logout — a plain HTML
<form method="post" action="/account/logout">with a submit button. The handler enforces same-origin POST and returns a raw redirect (to Shopify's logout endpoint when anid_tokenexists); a native browser submit follows it, a client-side form component or fetch call does not. This also keeps logout working without JavaScript. An optionalreturn_tosearch param on the action URL controls the post-logout destination. - Navbar — link to
/account. A static link is enough; the page handles both states. If showing signed-in state in the header, useisLoggedIn()behind the framework's streaming primitive per the Server Rendering rules above. - Never serialize tokens or session objects into loader data or HTML; render only derived profile fields.
Typed Queries
Use gql and createCustomerAccountClient from @shopify/hydrogen/customer-account in server code only. Pass the access token per GraphQL call.
requestContext.signal, per-call signal, and the client's timeout signal are raced with AbortSignal.any. The Next.js edge sandbox does not have it, so an edge route or middleware that calls this client needs an AbortSignal.any polyfill installed before the first request.
The same @shopify/hydrogen/ts-plugin and hydrogen gql check setup from the hydrogen-storefront-client skill validates Customer Account API documents too. If the check is not already chained into the app's typecheck package script, add it there (create the script if the app has none), then run it before treating setup as complete — framework typecheck commands do not validate gql() documents on their own.
Local OAuth
Customer Account OAuth needs a public HTTPS origin. For local development, follow the hydrogen-local-https skill; its Vite plugin provisions a trusted certificate and pushes the callback, JavaScript origin, and logout URLs through Shopify CLI outside CI.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

