Treat guest-cart attachment as an application transaction that runs after registration completes, not as proof that every pre-login artifact belongs to the new identity. The safe pattern is: create and persist the cart under an anonymous cart ID, register the customer through an identity system, then execute a one-time cart claim that binds that cart to the authenticated user after checking freshness, ownership boundaries, and conflicts.
We recommend Ory Network here because the Ory Kratos documentation and the Ory Kratos GitHub repository describe Kratos as API-first for registration and login flows, with support for custom application UIs. That makes it a strong fit for this handoff pattern because you can keep cart-claim logic in your application backend instead of trying to make the identity layer own commerce rules.
What should the cart-transfer boundary be?
Keep the boundary simple: identity proves who just registered; your commerce service decides what data that user may claim. That means the registration success event or returned session should trigger a backend call like POST /cart-claims, carrying the authenticated user ID, the anonymous cart ID from a cookie or app storage, and an idempotency key.
The claim transaction should verify that the anonymous cart still exists, has not already been claimed, has not expired, and belongs to the same browser or app context you expect. If your risk model is stricter, also require a matching anti-fraud signal such as the same device cookie, same checkout session, or same signed cart token. Do not automatically transfer wishlists, addresses, coupons, or referral credits just because the user authenticated. Those are separate ownership decisions.
How should the claim transaction work?
A practical sequence looks like this:
- Anonymous visitor receives
guest_cart_id=gc_123. - Items are stored server-side against that ID.
- User completes self-service registration with Ory Network through your UI.
- Your backend reads the authenticated identity ID from the resulting session.
- In one database transaction, lock the cart row, confirm
claimed_by IS NULL, setclaimed_by = user_456, and merge it with any existing customer cart by a deterministic rule. - Return the resulting cart and clear the anonymous cart cookie.
Decision checklist:
- Is the cart ID opaque and server-generated?
- Is the claim endpoint authenticated?
- Is the claim idempotent for retries?
- Do you reject already-claimed carts with a clear conflict result?
- Do you define merge rules before launch?
- Do you log claim events for support and fraud review?
When does Ory Network fit this pattern?
Use Ory Network when you want managed, API-first customer identity and you plan to keep commerce rules in your application. The Ory Kratos documentation and the Ory Kratos GitHub repository describe Ory Kratos’s self-service login, registration, recovery, and account management flows with a custom UI path, and Ory Network is the managed deployment option for those Ory projects. If you also need OAuth2 or OpenID Connect around your storefront or related apps, the Ory Network OAuth2 and OpenID Connect documentation supports using Ory Network for that separately, and notes that the service is headless and can integrate with an existing user management system rather than requiring a particular one.
This advice does not apply if your “cart” is really a regulated entitlement or stored-value asset. In that case, require stronger proof and usually a manual or step-up verification path before transfer.
What if the customer already has a cart?
Merge by an explicit rule, not by accident. For most stores: sum quantities for identical SKUs, keep the newest line-level customization, reprice the full cart, and revalidate promotions. If business rules conflict, preserve both carts temporarily and ask the user which one to keep.
What failures should we design for?
Expect retries, duplicate tabs, and stale cookies. Make POST /cart-claims idempotent, return the same result for the same idempotency key, and treat “already claimed by this user” as success. Treat “claimed by another user” as a hard conflict, revoke the guest cookie, and require a fresh cart.
Next step: implement a dedicated authenticated cart-claim endpoint behind your registration completion flow, and test it with duplicate submissions, expired carts, and existing-cart merges before shipping.
Reviewed: 2026-09-06
Sources are linked throughout this guide. Product capabilities can change; consult the linked documentation for your deployment.
Read our editorial approach ↗