> 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/developer-tools/next-js/sdk-reference/useuser.md).

# useUser

{% hint style="info" %}
**This page's documentation only applies to Chord's** [**Next.js starter**](https://github.com/chordcommerce/nextjs-starter-autonomy) **prior to the release of the** [React](/chord-oms/developer-tools/react.md)**. The Next.js starter now uses the React SDK and does not use the methods documented on this page. Check out the** [**React SDK Reference**](https://docs-beta.chord.co/chord-ui/module-react-autonomy) **for complete documentation, and the** [React SDK Migration Guide](/chord-oms/developer-tools/next-js/guides/react-sdk-migration-guide.md)**for details on how to upgrade.**
{% endhint %}

The `useUser` hook returns the current user and functions for loading data about the user. At the moment, the only user information Chord supports is the user's referral identifier and personalized referral url.

## Example

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

// inside a function component
const { user, loadUser } = useUser()
```

## Returns

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

| Property                | Description                                                                                        |
| ----------------------- | -------------------------------------------------------------------------------------------------- |
| `user`                  | An object representing the current user.                                                           |
| `loadUser`              | A function that loads information about the current order's associated user.                       |
| `loadUserIdentifier`    | A function that loads the referral identifier information for the current order's associated user. |
| `modifyUser`            | A function to update the user's profile information.                                               |
| `loadUserSubscriptions` | A function that loads the current user's subscriptions.                                            |

## Functions

### loadUser

The `loadUser` function loads information about the current order's associated user from the Chord API.

**Arguments:**

None.

**Returns:**

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

**Example**:

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

export default () => {
  const { cart } = useCart()
  const { user, loadUser } = useUser()

  useEffect(() => {
    loadUser()
  }, [])

  return <p>Welcome, {user.data.email}!</p>
}
```

### loadUserReferralIdentifier

The `loadUserReferralIdentifier` function loads the referral identifier information for a user with the given email address from the Chord API.

**Arguments:**

`loadUserReferralIdentifier(email)`

| Argument | Type   | Description                    |
| -------- | ------ | ------------------------------ |
| `email`  | String | The email address of the user. |

**Returns:**

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

**Example:**

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

export default () => {
  const { user, loadUserReferralIdentifier } = useUser()
  const referralPurl = user.referralIdentifier && user.referralIdentifier.purl

  useEffect(() => {
    loadUserReferralIdentifier()
  }, [])

  return (
    <p>Refer your friends with your personal referral link: {referralPurl}</p>
  )
}
```

### modifyUser

The `modifyUser` function is used to update the user's profile information.

**Arguments:**

`modifyUser(options)`

| Argument                 | Type   | Description                                                                                                                |
| ------------------------ | ------ | -------------------------------------------------------------------------------------------------------------------------- |
| `email?`                 | String | (Optional) The email address of the user.                                                                                  |
| `billAddressAttributes?` | Object | (Optional) An object representing the billing address. All fields need to be sent even if only a single field is updated.  |
| `shipAddressAttributes`? | Object | (Optional) An object representing the shipping address. All fields need to be sent even if only a single field is updated. |

**Returns**:

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

**Example:**

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

export default () => {
  const { modifyUser } = useUser()
  const onSubmit = ({ email }) => {
    modifyUser({ email })
  }

  // return profile edit form
}
```


---

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