Skip to content

Auth & roles

Merchant staff authenticate with Supabase Auth. Send the Supabase access JWT as a bearer token, plus x-organization-slug on tenant-scoped operations to pick which of your memberships you're acting on. Customer accounts use a separate opaque session, described below.

This example uses the Preview API and an enabled tenant Sandbox. Confirm your environment and commerce mode before making calls:

curl https://api.preview.litecommerce.io/api/v1/merchant/items \
  -H "Authorization: Bearer <supabase-jwt>" \
  -H "x-commerce-environment: sandbox" \
  -H "x-organization-slug: your-store"

The guard chain

Tenant-scoped merchant mutations normally use this guard chain:

  1. MerchantAuthGuard — validates the bearer JWT against Supabase Auth and resolves it to a cartonium user (lazily syncing the user row on first login).
  2. MembershipGuard — reads x-organization-slug and confirms the authenticated user has a membership in that organization. A missing or unknown slug, or no membership, returns the same 403 rejection.
  3. RolesGuard — enforces legacy route-role metadata when present and the newer permission-policy metadata on merchant mutations. Read endpoints are generally open to any member. Writes are open to Owner/Admin by default, and Staff can be delegated specific write capabilities through permission presets or direct permission groups.

Requirements vary by operation. For example, GET /api/v1/merchant/auth/session needs the staff JWT but no tenant header: it returns the caller's memberships before a tenant is selected. Some reads use the authentication and membership guards without a role policy. Check the API reference for the operation you call.

Built-in roles

cartonium ships three base roles:

RoleTypical use
OwnerFull control, including owner-only powers like billing and ownership transfer
AdminFull operational control across tenant settings, staff, merchandising, and operations
StaffRead-only baseline; write access comes from permission groups

Staff can hold memberships in multiple tenants and switch between them — useful for agencies and operators who work across brands.

Permission groups

Permission groups are the fine-grained layer below the base role. Owner/Admin members retain broad write access; Staff members start read-only and need one or more groups for merchant mutations:

GroupControls
catalog:writeProducts, variants, catalog media, collections, and item ordering
content:writeCMS page creation and edits
inventory:adjustStock adjustments, holds, releases, and low-stock thresholds
orders:operateOrder status, fulfillment operations, and internal notes
returns:operateReturn/RMA status and notes
reviews:moderateProduct review approval and rejection
pricing:writeCoupons, automatic discounts, sale windows, and bundles
customers:supportCustomer support workflows
shared-commerce:quotesQuote creation, revisions, delivery, acceptance, and voiding
shared-commerce:invoicesInvoice creation, collection, delivery, and voiding
shared-commerce:contractsContract preparation, delivery, countersigning, and signature management
shared-commerce:manual-paymentsRecording non-card payments and payment corrections
bookings:operateBooking setup, capacity preflight, assignments, and lifecycle mutations
bookings:overrideHigh-risk controlled-shortage actions; also requires bookings:operate
subscriptions:operateSubscription plans, customer subscriptions, renewals, pauses, and cancellations
subscriptions:overrideHigh-risk subscription price and lifecycle overrides
reports:viewReporting and operational analytics
settings:manageTenant settings and shipping configuration
team:manageTeammate invites and membership management
api-keys:manageTenant API key create/revoke operations

Shared-commerce, booking, and subscription surfaces use these groups in the same model. The built-in permission presets are composed from these groups; custom presets are a tenant-admin workflow.

Additional roles from the pre-permission model map to Staff during migration and should be treated as historical names only.

Choose the credential for the operation

SurfaceCredential and tenant context
Anonymous public catalog/contentNo credential; x-organization-slug selects the tenant
Tenant-scoped merchant operationsSupabase staff JWT plus x-organization-slug; membership and the operation's permission policy apply
Customer account operationsOpaque CustomerSession, separate from Supabase Auth, plus x-organization-slug
Emailed customer action linksThe purpose-bound action token plus x-organization-slug; no customer session is required
Checkout payment handoffThe checkout token resolves the session and tenant; this operation does not require x-organization-slug
Server-to-server storefront reads (staging implementation)Server-side only x-api-key; the tenant comes from the key

For BYO customer accounts, keep the opaque session bearer on your backend and proxy customer calls; never substitute a merchant JWT or expose the session to browser JavaScript. Hosted cartonium checkout provides its own account UI and server-side session forwarding. See Customer accounts & sign-in.

Inbound API-key authentication is implemented on staging for the separate /api/v1/storefront/* surface. Full self-serve productization remains in active development; a staging contract is not a Production availability claim. Keys do not replace staff JWTs on merchant routes. See API keys for the server-side contract and remaining work.

Endpoint-level auth and permission requirements are annotated in the API reference.