> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackfront.digital/llms.txt
> Use this file to discover all available pages before exploring further.

# Customer & Orders Overview

# Customer & Orders

The SDK provides authentication, profile management, and order history through the Shopify Storefront GraphQL API. Tokens are managed in-memory by the `CustomerService` and synced via `useStackfront().setCustomerAccessToken`.

## Quick Reference

| Hook            | Purpose                                             |
| --------------- | --------------------------------------------------- |
| `useCustomer()` | Login, logout, register, profile, password recovery |
| `useOrders()`   | Order history for logged-in customers               |

## Authentication Flow

1. **Register** — `createAccount({ email, password })` creates a customer via `CUSTOMER_CREATE`
2. **Login** — `login(email, password)` creates an access token via `CUSTOMER_ACCESS_TOKEN_CREATE`, syncs it to the SDK context and the cart's buyer identity
3. **Authed state** — `customer.getAccessToken()` returns the current token
4. **Logout** — `logout()` deletes the token on Shopify and clears it from memory

## Cart Integration

When a customer logs in, the SDK automatically:

* Sets the customer access token in the `CustomerService`
* Calls `setCustomerAccessToken` at the provider level
* Links the customer ID to the push notification device
* Tracks `login` and `logout` events

To associate the cart with the logged-in customer, call `updateBuyerIdentity` after login (available via `useCart`):

```ts theme={null}
const { cart } = useCart();
const { customer } = useStackfront();
await cart.updateBuyerIdentity({
  customerAccessToken: customer.getAccessToken(),
});
```
