Skip to main content

Overview

Customers interact with your store through the Store API. They can register, log in, manage their profile, and view order history.

Registration

const { token, user } = await client.store.auth.register({
  email: 'john@example.com',
  password: 'password123',
  password_confirmation: 'password123',
  first_name: 'John',
  last_name: 'Doe',
})
// token => JWT token for subsequent authenticated requests
// user => { id: "usr_xxx", email: "john@example.com", first_name: "John", ... }

Login

const { token, user } = await client.store.auth.login({
  email: 'john@example.com',
  password: 'password123',
})
// Use the token for authenticated requests
The response includes a JWT token and a user object. Pass the token in subsequent requests via the Authorization: Bearer <token> header.

Token Refresh

Refresh an expiring token to keep the session alive:
const { token } = await client.store.auth.refresh({
  token: existingToken,
})

Customer Profile

// Get current customer
const customer = await client.store.customer.get()
// {
//   id: "usr_xxx",
//   email: "john@example.com",
//   first_name: "John",
//   last_name: "Doe",
//   default_shipping_address: { ... },
//   default_billing_address: { ... },
//   addresses: [{ ... }, { ... }],
// }

// Update profile
const updated = await client.store.customer.update({
  first_name: 'Jonathan',
  accepts_email_marketing: true,
})

Customer Resources

Authenticated customers have access to these resources:
ResourceDescription
AddressesBilling and shipping addresses with default selection
OrdersPast order history
Credit CardsSaved credit cards for checkout
Payment SourcesOther saved payment methods (PayPal, Klarna, etc.)
Store CreditsBalance assigned by the store, usable at checkout
Gift CardsGift cards owned by or assigned to the customer
WishlistsSaved product lists

Guest Checkout

Customers don’t need to register to purchase. Guest checkout uses an order token (X-Spree-Order-Token) to identify the cart. See Orders — Cart for details.