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

# Overview

> Customer authentication and account management using Shopify as your identity provider

```javascript theme={null}
openbridge.customer
```

Full customer authentication system using Shopify's Storefront API. No backend required - Shopify is your user database.

<Info>See [Types](/api/types/customer) for full interface definitions.</Info>

## 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

<CardGroup cols={2}>
  <Card title=".init()" href="/api/customer/init">
    Initialize customer session
  </Card>

  <Card title=".login()" href="/api/customer/login">
    Log in with email and password
  </Card>

  <Card title=".register()" href="/api/customer/register">
    Create new customer account
  </Card>

  <Card title=".logout()" href="/api/customer/logout">
    Log out current customer
  </Card>

  <Card title=".get()" href="/api/customer/get">
    Get current customer profile
  </Card>

  <Card title=".isLoggedIn()" href="/api/customer/is-logged-in">
    Check if a customer is logged in
  </Card>

  <Card title=".getCached()" href="/api/customer/get-cached">
    Get the cached customer synchronously
  </Card>

  <Card title=".getToken()" href="/api/customer/get-token">
    Get the raw access token
  </Card>

  <Card title=".update()" href="/api/customer/update">
    Update customer profile
  </Card>

  <Card title=".orders()" href="/api/customer/orders">
    Get order history
  </Card>

  <Card title=".addresses()" href="/api/customer/addresses">
    List customer addresses
  </Card>

  <Card title=".addAddress()" href="/api/customer/addresses#add-address">
    Add a new shipping address
  </Card>

  <Card title=".updateAddress()" href="/api/customer/addresses#update-address">
    Update an existing address
  </Card>

  <Card title=".deleteAddress()" href="/api/customer/addresses#delete-address">
    Remove a saved address
  </Card>

  <Card title=".setDefaultAddress()" href="/api/customer/addresses#set-default-address">
    Set the default shipping address
  </Card>

  <Card title=".recover()" href="/api/customer/recover">
    Send password reset email
  </Card>

  <Card title=".reset()" href="/api/customer/reset">
    Reset password with token
  </Card>

  <Card title=".subscribe()" href="/api/customer/subscribe">
    Listen for auth changes
  </Card>
</CardGroup>

## Quick Example

```javascript theme={null}
// Initialize on page load - auto-restores session
const customer = await openbridge.customer.init()

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

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

// Login
const customer = await openbridge.customer.login('email@example.com', 'password')

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

// Logout
await openbridge.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

<Warning>
  Access tokens expire after a period set by Shopify (typically 2 weeks). The SDK automatically clears expired tokens.
</Warning>
