Skip to main content
The customer address book: list, default address, and the full create / update / delete / set-default CRUD — all against the Shopify Storefront API.

Address book

Every mutation invalidates the address cache and the cached customer profile, so all mounted screens agree immediately. The list and the default address come from one Storefront request. While signed out the hook never fetches and returns empty data.

Create form

validateAddress(input) is pure and returns { isValid, errors: Record<field, message> } — the same shape the reference package used, so form code ports over directly. Required fields: first name, last name, address line 1, city, country, zip. Province is optional (countries without subdivisions) and only format-checked when supplied. validateAddressUpdate(input) checks partial update payloads: blank required fields are rejected when present, formats are validated, untouched fields are ignored. The service calls the right validator automatically; an invalid input never reaches the network.

Single address and default

useAddress matches by base GID (see the note below), and shares the address-book cache — opening a detail screen from the list does not refetch.

Address model

Helpers exported for rendering:
  • formatAddress(address) — multiline display string
  • formatPhone(phone) — (555) 123-4567 for 10-digit US numbers
  • normalizeAddress(raw, defaultAddressId?) — raw node → model
  • addressBaseId(id) / sameAddressId(a, b) — token-safe comparison
Shopify’s MailingAddress.id looks like gid://shopify/MailingAddress/123?model_name=CustomerAddress&customer_access_token=… and the token changes on every response. Always pass an id back to the SDK as you received it; never compare ids with ===. The SDK compares base GIDs internally, and isDefault is computed the same way.

Service API

All methods renew a near-expiry customer token first and throw 'Not authenticated' without a session. Shopify-side rejections throw an AddressUserError whose userErrors array keeps the code, field and message for each problem, so a form can map messages to inputs.