Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
---
title: Authentication
description: Authentication modes and guest checkout with the Spree SDK
---
import SdkClientSetup from '/snippets/store-api/sdk-client-setup.mdx'
import AuthJwtExample from '/snippets/store-api/auth-jwt-example.mdx'
import AuthGuestCart from '/snippets/store-api/auth-guest-cart.mdx'
The SDK supports multiple authentication modes depending on your use case. For a full overview of the API authentication methods, see the [Store API Authentication](/api-reference/store-api/authentication) reference.
## Publishable Key Only (Guest/Public Access)
Use a publishable API key for public endpoints like browsing products:
<SdkClientSetup />
```typescript
// Public endpoints work without user authentication
const products = await client.products.list()
```
## Publishable Key + JWT (Authenticated Customer)
For authenticated customer actions like viewing orders or managing addresses:
<AuthJwtExample />
```typescript
// Exchange the refresh_token returned by login for a new access token.
// The refresh token rotates, so store the new one as well.
const { token: newToken, refresh_token: newRefreshToken } = await client.auth.refresh({
refresh_token: refreshToken,
})
```
## Register New Customer
```typescript
const { token, user } = await client.customers.create({
email: '[email protected]',
password: 'password123',
password_confirmation: 'password123',
first_name: 'John',
last_name: 'Doe',
})
```
## Guest Checkout
For guest checkout, use the `token` returned when creating a cart. The SDK automatically sends it via the `x-spree-token` header:
<AuthGuestCart />
```typescript
const options = { spreeToken: cart.token }
// Update cart with email
await client.carts.update(cart.id, {
email: '[email protected]',
}, options)
// Complete checkout
await client.carts.complete(cart.id, options)
```