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

# .init()

> Initialize customer session and restore login state

```javascript theme={null}
openbridge.customer.init()
```

Initializes the customer session by checking for a stored access token. If a valid token exists, fetches and returns the customer data. Call this on page load to restore logged-in state.

## Returns

`Promise<ShopifyCustomer | null>` - Customer object if logged in, `null` otherwise.

## Examples

### Basic initialization

```javascript theme={null}
// On page load
const customer = await openbridge.customer.init()

if (customer) {
    console.log(`Logged in as ${customer.email}`)
    showAccountMenu()
} else {
    showLoginForm()
}
```

### Handling an expired session

`.init()` never throws — if the stored token is invalid or expired, the token is cleared and `null` is returned.

```javascript theme={null}
const customer = await openbridge.customer.init()

if (customer) {
    updateUI(customer)
} else {
    // No valid session — show the logged-out state
    showLoginForm()
}
```

### Combined with subscribe

```javascript theme={null}
// Set up subscription first
openbridge.customer.subscribe((customer) => {
    updateNavbar(customer)
})

// Then initialize - will trigger subscriber with restored state
await openbridge.customer.init()
```

<Info>
  Always call `.init()` early in your page lifecycle. This restores the customer session and triggers any subscribers with the current state.
</Info>
