Skip to content

Customer accounts & sign-in

Storefront requests also carry their current origin: browsers supply Origin; SSR and backend transports forward x-storefront-origin. Domains selects Live or Sandbox data automatically, including token-only calls. Missing or conflicting context is rejected, with no Live fallback. See storefront data selection.

cartonium gives each tenant's shoppers a passwordless customer account: they sign in with a magic link or a one-time code (no password to store or reset), and the session unlocks their profile, saved addresses, order history, and returns. The same API backs both hosted cartonium checkout and a BYO storefront.

Customer accounts are separate from merchant accounts. A merchant user (Owner/Admin/Staff) signs in to the admin with a Supabase JWT; a customer signs in to the storefront/checkout surface with a customer session. They are different identities, different tokens, and different endpoints.

All paths below are under /api/v1. Every call carries x-organization-slug — customer identities are tenant-scoped, so a session minted for one tenant is meaningless to another.

The session credential

A customer session is an opaque token, hashed at rest (ADR-007). The API's verify response returns the raw bearer once and also sets an httpOnly, Secure, SameSite=Lax __Host- cookie on the API response's origin.

  • Hosted cartonium checkout verifies through its own same-origin server route. That route writes the token into the hosted origin's httpOnly cookie and returns expiry metadata to browser JavaScript, without echoing the bearer. A cookie set by a direct call to the API origin does not establish a session on the hosted origin.
  • BYO storefronts verify through their own backend, retain the bearer server-side, and proxy customer calls with Authorization: Bearer <token>. Use a secure session mechanism between your browser and backend; origin-bound cookies do not transfer between storefront, API, and hosted checkout origins.

Keep the customer-session bearer server-side. Do not expose it in client JavaScript, browser storage, URLs, or logs. Merchant JWTs and tenant API keys do not replace this customer credential.

Sign-in flow (passwordless)

These examples use the Preview API deployment and a storefront address registered in the tenant's Production entry in Domains. Replace the example origin with that verified address; it selects Live commerce data on this API deployment. There is no default-to-Live fallback, and the Preview API hostname does not select Sandbox. Challenge delivery still requires an allowed recipient and configured delivery policy; external email is disabled in Sandbox. See Environments & schema identity.

1. Request a challenge

Two issuers, both anonymous (no session yet), both under /api/v1/public/customer/auth:

  • POST /public/customer/auth/request-link — sends a one-click magic-link email, with a fallback OTP.
  • POST /public/customer/auth/request-otp — sends a short-lived numeric one-time code.
curl -X POST https://api.preview.litecommerce.io/api/v1/public/customer/auth/request-link \
  -H "x-storefront-origin: https://shop.your-store.example" \
  -H "x-organization-slug: your-store" \
  -H "Content-Type: application/json" \
  -d '{ "email": "shopper@example.com" }'

Successful issuance requests return the same neutral 200 regardless of whether the email belongs to a customer of this tenant. This is deliberate: the response can't be used to enumerate accounts. Don't branch your UI on it — show "check your email" either way. Validation, rate-limit, and availability errors still need their normal error handling; a neutral response is not proof of inbox delivery.

2. Verify and start a session

POST /public/customer/auth/verify accepts either shape:

  • { "token": "<magic-link-token>" } — from the emailed link, or
  • { "email": "...", "code": "<otp>" } — from the one-time code.
curl -X POST https://api.preview.litecommerce.io/api/v1/public/customer/auth/verify \
  -H "x-storefront-origin: https://shop.your-store.example" \
  -H "x-organization-slug: your-store" \
  -H "Content-Type: application/json" \
  -d '{ "email": "shopper@example.com", "code": "123456" }'

On success the API mints a fresh session and returns token, expiresAt, idleExpiresAt, persistent, and customerId. Use the server-side transport described above. A bad or expired token/code returns a neutral 401; the issue-and-verify surface also has rate limits. Do not infer the account's existence from a failed verification.

Session lifetime and persistence

The current staging contract enforces two deadlines:

Verify choiceIdle windowAbsolute window
Omit persistSession, or send false6 hours24 hours
Send literal boolean persistSession: true after an affirmative "Keep me signed in" choice30 days365 days

expiresAt is the fixed absolute deadline. idleExpiresAt advances on authenticated use, capped by expiresAt; the session expires when either deadline passes. Cookie retention does not override those server checks, and logout or revocation can end access earlier. Do not infer persistence from a remembered email, browser state, or a previous session. This is an API option, not a claim that every hosted sign-in UI offers a persistence control.

3. Use the session

Account calls under /api/v1/customer/account/* require the session (cookie or bearer) plus x-organization-slug. Tokenized action routes under /customer/actions/* use their own credential, as described below.

curl https://api.preview.litecommerce.io/api/v1/customer/account/profile \
  -H "x-storefront-origin: https://shop.your-store.example" \
  -H "x-organization-slug: your-store" \
  -H "Authorization: Bearer <session-token>"

POST /customer/auth/logout ends the session (clears the cookie / revokes the token).

The account API

All authenticated, all tenant-scoped to the signed-in customer — a session can only ever read or write its own data.

Profile

  • GET /customer/account/profile — read name, email, phone, email-verified state.
  • PATCH /customer/account/profile — update the customer's own profile fields.

Addresses

A customer keeps an address book with default shipping/billing flags.

  • GET /customer/account/addresses — list saved addresses.
  • GET /customer/account/addresses/:id — read one.
  • POST /customer/account/addresses — add an address.
  • PATCH /customer/account/addresses/:id — update an address.
  • DELETE /customer/account/addresses/:id — remove an address.

Order history

  • GET /customer/account/orders — paginated list of the customer's orders.
  • GET /customer/account/orders/by-reference/:orderReference — one order's detail (items, totals, status), addressed by its stable public orderReference.
  • GET /customer/account/orders/:orderNumber — the same detail addressed by the display order number (supported compatibility route).

Every order response carries two identities:

  • orderReference (or1_ + 32 lowercase hex) — the stable, customer-safe public address for the order. Use it in URLs and handoffs. It is not a credential: possession alone never grants access, and unknown, malformed, cross-tenant, and unowned references all return the same neutral 404 after authentication. null only on legacy orders that predate the reference backfill.
  • orderNumber — the human-facing display number. Show it to customers; don't use it as a routing identity in newly generated URLs.

Orders are matched to the customer, so the list only ever contains their own orders — there's no cross-customer lookup on this surface.

Returns

By-reference routes are the primary family for new integrations; the order-number routes remain supported for compatibility.

The following factual companions are in the current staging contract. Verify the reference and environment's schema identity before adopting them; this guide does not establish deployed availability or consumer adoption. Each account operation requires a live tenant-bound CustomerSession and durable ownership of the exact parent Order. Neither an order reference nor a matching email replaces that authorization. The cancelled Return must also belong to that exact tenant and Order.

OperationRequestSuccess response
GET /customer/account/orders/by-reference/{orderReference}/returns/factsNo body200, CustomerReturnFactsListByReferenceResponseDto: data: CustomerReturnFactsByReferenceDto[]
POST /customer/account/orders/by-reference/{orderReference}/returns/factsRequired CreateReturnByReferenceDto body201, one OrderReferenceReturnFactsDto with no data wrapper
POST /customer/account/orders/by-reference/{orderReference}/returns/{returnId}/cancel/factsBodyless; no email credential200, one OrderReferenceReturnFactsDto with no data wrapper
GET /customer/account/orders/{orderNumber}/returns/factsNo body; supported number-addressed compatibility read200, CustomerReturnFactsListResponseDto: data: CustomerReturnFactsDto[]

Both lists are newest first and return data: [] when the owned order has no Returns. Do not parse these as the public compatibility API's bare array. By-reference responses retain orderReference and omit raw orderId; number-addressed and token response identities retain their own schema shapes. Do not collapse the families into a handwritten universal Return type.

Create requires items (1–50 lines, each with orderItemId and positive quantity), with optional customerName, reason and reviewedEstimate. It deliberately accepts no customerEmail. Quantities remain subject to existing unreturned-capacity checks. reviewedEstimate is the exact selection and estimate the customer deliberately reviewed; it supplies no calculation authority. Omission leaves requested money NOT_CAPTURED, not an unseen acknowledgement. An AVAILABLE acknowledgement includes its historical currency, amount and supported breakdown; UNAVAILABLE carries no monetary values. Use the reference DTO for the complete shape.

// Reuse the api() helper; forward the actual verified storefront origin.
// Account calls use the customer-session bearer server-side, not a merchant JWT.
const created = await api<{ id: string }>(
  `/customer/account/orders/by-reference/${orderReference}/returns/facts`,
  {
    method: "POST",
    token: customerSession,
    storefrontOrigin,
    body: JSON.stringify({ items: [{ orderItemId, quantity: 1 }] }),
  },
); // 201, OrderReferenceReturnFactsDto; no monetary acknowledgement supplied
 
await api(
  `/customer/account/orders/by-reference/${orderReference}/returns/${created.id}/cancel/facts`,
  { method: "POST", token: customerSession, storefrontOrigin }, // bodyless
);

Customer cancellation is allowed only while REQUESTED or APPROVED.

Unknown, malformed, unowned and cross-tenant references keep the neutral authenticated 404; an absent/expired session is 401. Preserve validation, conflict, rate-limit and readiness handling from each operation's reference, including declared Retry-After headers on account-reference refusals. RETURN_REQUESTED_REVIEW_STALE is a 409 that created no Return: review the selection/estimate again before resubmitting. It is not permission to skip acknowledgement or manufacture a zero. Origin refusals are separate from session and ownership checks.

The factual money and physical guide explains immutable requested evidence, current and historical published approvals, actual refunds/corrections, historical currency, genuine zero versus unavailable, and independent physical/completion versions. These same facts appear on account and token responses. Never fall back to the old top-level private-draft scalars when a fact is unavailable or a request is refused. Factual responses are private and non-cacheable (Cache-Control: private, no-store); do not put customer/token results in a shared cache.

Action issuance and legacy compatibility

Action issuance is unchanged:

  • POST /customer/account/orders/by-reference/:orderReference/return-actions — issue a purpose-bound return action token for eligible items. The raw token is returned once in the response — nothing is emailed — and the caller can consume it at /customer/actions/:token/facts (hosted cartonium checkout navigates straight to its /action/{token} page).
  • POST /customer/account/orders/:orderNumber/return-actions — the supported number-addressed compatibility issuer; it also requires session ownership.

The original account list, by-reference create/cancel and number list routes without /facts remain supported compatibility shapes, as does legacy token consumption. Their old money scalar meanings/nullability are unchanged; they are not factual response fallbacks. Public email-gated routes (including their factual companions) remain deprecated; see Returns. This documentation selects no notice/removal dates and starts no sunset clock; the API lifecycle policy governs any retirement. The retained contract snapshot provides the immutable eight-operation packet, manifest and OpenAPI subset. Its pinned full-schema identity is separate from any later full reference and from unverified publication, served-version and adoption evidence.

Bookings

In active development: these routes are present in the current staging contract. Bookings are not launch-complete; the shipped customer-account capability does not make every booking action available in Production.

  • GET /customer/account/bookings — paginated booking history, optionally by status.
  • GET /customer/account/bookings/:id — customer-safe schedule, delivery, policy actions, documents, agreements, and Sales/payment summary.
  • POST /customer/account/bookings/:id/cancel-request — apply or request cancellation under the current policy.
  • POST /customer/account/bookings/:id/reschedule-request — request a changed window while preserving the booked duration.
  • GET /customer/account/booking-groups — paginated atomic-group history.
  • GET /customer/account/booking-groups/:publicRef — one owned group's detail.
  • POST /customer/account/booking-groups/:publicRef/resume — mint a fresh scoped resume proof for an owned group.

The server decides whether a booking action is available and whether it is immediate or merchant-reviewed. See Booking availability, holds & lifecycle.

Saved payment methods

Saved-card account management uses the customer session and tenant context, under /customer/payment-methods:

  • GET /customer/payment-methods — list customer-safe card metadata.
  • POST /customer/payment-methods/setup-intent — create a SetupIntent and return its clientSecret, stripeAccountId, and setup correlation fields.
  • PATCH /customer/payment-methods/:id/default — choose a default saved card.
  • DELETE /customer/payment-methods/:id — remove a card; 409 means an active payment dependency blocks removal.

Collect card data through Stripe Payment Element, initialized for the returned connected account. Keep card numbers and CVC out of cartonium requests. Creating or confirming a SetupIntent is not a checkout payment. Persisted card state comes from the setup webhook or the list endpoint's bounded reconciliation; a browser callback alone does not prove the card was saved.

The current staging implementation additionally provides a reviewed account-card setup through three routes. This extension remains pending exact-build hosted and PC-29 acceptance; it is separate from basic saved-card management and is not released hosted adoption guidance:

  • POST /customer/payment-methods/setup-attempts/:setupHandle/review — bind the exact SetupIntent and reviewed billing copy before confirmation, with separate saveAddress and makeDefaultBilling choices.
  • GET /customer/payment-methods/setup-attempts/:setupHandle?setupIntentId=… — read that exact setup's setupStatus, cardProjection, addressSave, and defaultBilling outcomes from the server.
  • POST /customer/payment-methods/setup-attempts/:setupHandle/address-save — consume the still-valid reviewed address choice after proven setup success.

Keep the returned setup handle paired with its exact SetupIntent. A billing correction starts a new setup; it does not edit an existing review. Saving an address is separate from saving a card, selecting a default card, or changing a shipping address. Do not repeat an uncertain address-save write or replay lost consent after a reload: read saved cards and addresses and follow the reported outcome. See the API reference for request fields and outcome meanings.

Account card management does not activate the separate dormant saved-card checkout flow.

Tokenized actions (no sign-in required)

Some customer actions are reached from an emailed link rather than a signed-in session — the link carries an opaque, single-purpose token (the a token family, ADR-007: hashed at rest, expiring, tenant-scoped). This is how, for example, a "start your return" email works without forcing a login.

  • GET /customer/actions/:token — preview what the token will do (the action + its context). A safe read, no mutation.
  • POST /customer/actions/:token — legacy consumption response, retained for compatibility.

The factual consumption contract is:

OperationRequestSuccess response
POST /customer/actions/{token}/factsOptional ConsumeReturnActionDto body; its reviewedEstimate is also optional200, CustomerActionConsumeFactsResponseDto with required action, status and returnRequest: CustomerReturnFactsDto

This is the eighth factual operation across this guide and the three public companions. The action token itself is the credential; a CustomerSession is not required and this capability does not grant account access. Tenant slug and actual origin context still apply. Do not use a merchant JWT or an order reference as the token.

Omitting the body (or reviewedEstimate) makes no monetary acknowledgement; a new Return has requested money NOT_CAPTURED. Supplying an acknowledgement means the customer deliberately reviewed that exact estimate/selection; the server validates it again. 409 / RETURN_REQUESTED_REVIEW_STALE means no Return was created: review again and reuse the same token. Other conflicts need their documented correction or order reload.

Consumption acts once. A deliberate replay of the same scoped token through either consume operation returns the same Return without acting again. After an uncertain response, retain and reuse that token rather than issuing a replacement token or creating another Return. Replay retains the original immutable requested evidence even if a different acknowledgement is supplied; approval and refund facts show their current state, so the response need not be byte-identical. A replay is neither a fresh review nor a second submission. Do not replay automatically on page view or run create/cancel as a read.

For first consumption, unknown, expired, revoked and cross-tenant tokens return the same neutral 404 after valid tenant/origin context. A token with a committed result follows the replay behavior above. Handle origin/validation refusals and the documented 409 separately; parse the standard error envelope when implementing review/retry UI rather than relying on the tiny helper's status-only error.

The read-only order-status link (the o token, sent with the order-confirmation email) follows the same hash-at-rest pattern but is a pure read — see Order status links.

Hosted vs BYO

  • Hosted cartonium checkout provides the optional account UI: profile, addresses, order history, returns, and saved payment methods. Link to the resolved account URL and let that origin establish its own customer session. Booking extensions retain the staging qualification above. The hosted exact-order destination is /account/orders/by-reference/{orderReference}: link a customer's order there with the orderReference from any API response. Hosted sign-in never puts a customer email in a URL; the sign-in page's code entry returns to that exact order, while an ordinary emailed sign-in link currently lands on hosted order history. See Hosted cartonium checkout.
  • BYO storefront calls these endpoints directly. Proxy them through your own backend so the session token (bearer) stays server-side; never call /customer/* from client JavaScript with the raw token.