Skip to main content
shoppy.customer
Full customer authentication system using Shopify’s Storefront API. No backend required - Shopify is your user database.
See Types for full interface definitions.

Features

  • No Backend Needed - Shopify handles all user data and authentication
  • Session Persistence - Customer stays logged in across browser sessions
  • Reactive Updates - Subscribe to auth state changes for automatic UI updates
  • Full Account Access - Orders, addresses, profile management

Methods

Quick Example

// Initialize on page load - auto-restores session
const customer = await shoppy.customer.init()

if (customer) {
    console.log(`Welcome back, ${customer.firstName}!`)
} else {
    console.log('Not logged in')
}

// Subscribe to auth changes
shoppy.customer.subscribe((customer) => {
    if (customer) {
        showAccountMenu(customer)
    } else {
        showLoginButton()
    }
})

// Login
const customer = await shoppy.customer.login('[email protected]', 'password')

// Get order history
const { orders } = await shoppy.customer.orders()

// Logout
await shoppy.customer.logout()

How It Works

  1. Customer logs in → Shopify validates credentials and returns an access token
  2. Token stored locally → Saved in localStorage with expiration
  3. Token auto-restores → Call .init() on page load to restore session
  4. Token used for API calls → All customer operations use the stored token
Access tokens expire after a period set by Shopify (typically 2 weeks). The SDK automatically clears expired tokens.