> For the complete documentation index, see [llms.txt](https://docs.chord.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chord.co/chord-oms/shopify/developer-tools/next-js/sdk-reference/useuser.md).

# useUser

The `useUser` hook returns the current user and functions for managing a Shopify customer account. The customer must have an active authentication session (see `useAuth`) for these methods to work.

## Example

{% code title="useUser" %}

```javascript
import { useUser } from '~/hooks/actions'

const {
  user,
  status,
  createUserAddress,
  loadUser,
  modifyUserAddress,
  modifyUserDefaultAddress,
  removeUserAddress
} = useUser()
```

{% endcode %}

## Returns

The `useUser` hook returns an object with these properties:

| Property                   | Description                                                                                                    |
| -------------------------- | -------------------------------------------------------------------------------------------------------------- |
| `user`                     | An object representing the current user.                                                                       |
| `status`                   | A string indicating whether the user's profile is currently being fetched.                                     |
| `createUserAddress`        | A function that adds a new address to the Shopify customer's address book.                                     |
| `loadUser`                 | A function that loads information about the current order's associated user.                                   |
| `modifyUserAddress`        | A function that updates an address in the Shopify customer's address book.                                     |
| `modifyUserDefaultAddress` | A function that updates which address is marked as the default address in the Shopify customer's address book. |
| `removeUserAddress`        | A function that removes an address from the Shopify customer's address book.                                   |

## Functions

### createUserAddress

The `createUserAddress` function adds a new address to the Shopify customer's address book.

**Arguments:**

`createUserAddress(address, isDefaultAddress)`

| Argument             | Type    | Description                                                                                                         |
| -------------------- | ------- | ------------------------------------------------------------------------------------------------------------------- |
| `address`            | Object  | New address.                                                                                                        |
| `address.address1?`  | String  | (Optional) First line of address.                                                                                   |
| `address.address2?`  | String  | (Optional) Second line of address.                                                                                  |
| `address.city?`      | String  | (Optional) City of address.                                                                                         |
| `address.company?`   | String  | (Optional) Company of address.                                                                                      |
| `address.country?`   | String  | (Optional) Country of address.                                                                                      |
| `address.firstName?` | String  | (Optional) First name of address.                                                                                   |
| `address.lastName?`  | String  | (Optional) Last name of address.                                                                                    |
| `address.phone?`     | String  | (Optional) Phone number of address.                                                                                 |
| `address.province?`  | String  | (Optional) Province or state of address.                                                                            |
| `address.zip?`       | String  | (Optional) Zip code of address.                                                                                     |
| `isDefaultAddress?`  | Boolean | (Optional) Boolean indicating whether this address should be the default address for the user. Defaults to `false`. |

**Returns:**

`Promise<void>`: A Promise that resolves when the user address has been added.

**Example:**

{% code title="createUserAddress" %}

```javascript
import { useUser } from '~/hooks/actions'

const { createUserAddress } = useUser()

const address = {
  address1: '',
  address2: '',
  city: '',
  company: '',
  country: '',
  firstName: '',
  lastName: '',
  phone: '',
  province: '',
  zip: ''
}
const isDefaultAddress = false
await createUserAddress(address, isDefaultAddress)
```

{% endcode %}

### loadUser

The `loadUser` function reloads the current user. This is automatically called on every page load and with every other `useUser` method.

**Arguments:**

None.

**Returns:**

`Promise<void>`: A Promise that resolves when the `user` object has been added to Redux.

**Example:**

{% code title="loadUser" %}

```javascript
import { useUser } from '~/hooks/actions'

const { loadUser } = useUser()
await loadUser()
```

{% endcode %}

### modifyUserAddress

The `modifyUserAddress` function updates an address in the Shopify customer's address book.

**Arguments:**

`modifyUserAddress(addressId, address, isDefaultAddress)`

| Argument             | Type    | Description                                                                                                         |
| -------------------- | ------- | ------------------------------------------------------------------------------------------------------------------- |
| `addressId`          | String  | Address ID.                                                                                                         |
| `address`            | Object  | Modified address.                                                                                                   |
| `address.address1?`  | String  | (Optional) First line of address.                                                                                   |
| `address.address2?`  | String  | (Optional) Second line of address.                                                                                  |
| `address.city?`      | String  | (Optional) City of address.                                                                                         |
| `address.company?`   | String  | (Optional) Company of address.                                                                                      |
| `address.country?`   | String  | (Optional) Country of address.                                                                                      |
| `address.firstName?` | String  | (Optional) First name of address.                                                                                   |
| `address.lastName?`  | String  | (Optional) Last name of address.                                                                                    |
| `address.phone?`     | String  | (Optional) Phone number of address.                                                                                 |
| `address.province?`  | String  | (Optional) Province or state of address.                                                                            |
| `address.zip?`       | String  | (Optional) Zip code of address.                                                                                     |
| `isDefaultAddress?`  | Boolean | (Optional) Boolean indicating whether this address should be the default address for the user. Defaults to `false`. |

**Returns:**

`Promise<void>`: A Promise that resolves when the user address has been modified.

**Example:**

{% code title="modifyUserAddress" %}

```javascript
import { useUser } from '~/hooks/actions'

const { modifyUserAddress } = useUser()

const addressId = '123'
const address = {
  address1: '',
  address2: '',
  city: '',
  company: '',
  country: '',
  firstName: '',
  lastName: '',
  phone: '',
  province: '',
  zip: ''
}
const isDefaultAddress = false
await modifyUserAddress(addressId, address, isDefaultAddress)
```

{% endcode %}

### modifyUserDefaultAddress

The `modifyUserDefaultAddress` function updates which address is marked as the default address in the Shopify customer's address book.

**Arguments:**

`modifyUserDefaultAddress(addressId)`

| Argument    | Type   | Description |
| ----------- | ------ | ----------- |
| `addressId` | String | Address ID. |

**Returns:**

`Promise<void>`: A Promise that resolves when the user address has been modified.

**Example:**

{% code title="modifyUserDefaultAddress" %}

```javascript
import { useUser } from '~/hooks/actions'

const { modifyUserDefaultAddress } = useUser()

const addressId = '123'
await modifyUserDefaultAddress(addressId)
```

{% endcode %}

### removeUserAddress

The `removeUserAddress` function removes an address from the Shopify customer's address book.

**Arguments:**

`removeUserAddress(addressId)`

| Argument    | Type   | Description |
| ----------- | ------ | ----------- |
| `addressId` | String | Address ID. |

**Returns:**

`Promise<void>`: A Promise that resolves when the user address has been removed.

**Example:**

{% code title="removeUserAddress" %}

```javascript
import { useUser } from '~/hooks/actions'

const { removeUserAddress } = useUser()

const addressId = '123'
await removeUserAddress(addressId)
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.chord.co/chord-oms/shopify/developer-tools/next-js/sdk-reference/useuser.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
