Cartesiandocs

Your Cartesian backend

Sessions and tokens

How shopper sessions reach the SDK, and how each vertical sends them.

The SDK only ever receives a session token. It never handles passwords, API secrets or partner keys.

Flow

  1. The shopper signs in to your app as usual.
  2. Your app asks your backend for a Cartesian session for that shopper.
  3. Your backend creates the session on the Cartesian backend (server to server) and returns the token.
  4. Your app calls Cartesian.client.signIn(token).

How the token is sent

VerticalRESTWebSocket
GroceryCookie: grocery_session=<token>The same cookie on the upgrade request
ApparelAuthorization: Bearer <token>Sec-WebSocket-Protocol: bearer.<token>

Browsers (React SDK)

Browsers can't attach a cookie to a request for another domain, and the grocery backend currently reads the session only from the grocery_session cookie and sends no CORS headers. Until it accepts bearer tokens for REST and the bearer.<token> WebSocket subprotocol, web apps must reach the grocery backend through a same-origin proxy: a path on your own domain, such as /cartesian, that forwards /api/* and /ws and adds the cookie. See React installation. Android, iOS and the apparel backend aren't affected.

Validation

On signIn and at every launch the SDK calls GET /api/auth/session. It expects:

{ "user": { "id": "u_123", "email": "sam@example.com", "displayName": "Sam" } }
json
  • 200 means the session is valid.
  • 401 means the token is invalid. The SDK clears it and reports SignedOut.
  • 5xx or a network error means the SDK keeps the token and tries again later. The shopper stays signed in.

Lifetime

Make tokens last at least as long as your app's own session. When one expires, the next call returns 401, the SDK calls onSignInRequired(), and your app can fetch a new one silently.