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

# .login()

> Authenticate customer with email and password

```javascript theme={null}
openbridge.customer.login(email, password)
```

Authenticates a customer using their email and password. On success, stores the access token and returns the customer data.

## Parameters

| Param      | Type     | Required | Description              |
| ---------- | -------- | -------- | ------------------------ |
| `email`    | `string` | Yes      | Customer's email address |
| `password` | `string` | Yes      | Customer's password      |

## Returns

`Promise<ShopifyCustomer>` - The authenticated customer object.

## Throws

* `Error` - If credentials are invalid or login fails.

## Examples

### Basic login

```javascript theme={null}
try {
    const customer = await openbridge.customer.login(
        'customer@example.com',
        'password123'
    )

    console.log(`Welcome, ${customer.firstName}!`)
    redirectToDashboard()
} catch (error) {
    showError(error.message) // "Unidentified customer"
}
```

### Login form handler

```javascript theme={null}
document.querySelector('#login-form').addEventListener('submit', async (e) => {
    e.preventDefault()

    const email = document.querySelector('#email').value
    const password = document.querySelector('#password').value

    try {
        await openbridge.customer.login(email, password)
        window.location.href = '/account'
    } catch (error) {
        document.querySelector('#error').textContent = error.message
    }
})
```

### Check if already logged in

```javascript theme={null}
if (openbridge.customer.isLoggedIn()) {
    // Already authenticated
    redirectToAccount()
} else {
    // Show login form
    showLoginForm()
}
```

<Warning>
  Never store passwords. The SDK only sends credentials to Shopify's secure API and stores only the resulting access token.
</Warning>
