---
title: useUser
slug: oms/useuser
docTags: 
createdAt: 2022-11-07T21:27:00.000Z
---

:::hint{type="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&#x20;**[React](docId\:EwXkRz0JhH0zPphIkkcrI)**. 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&#x20;**[React SDK Migration Guide](docId\:qMilHJFPz9WbJYZbe50Ku)**for details on how to upgrade.**
:::

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&#x20;

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&#x20;

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&#x20;

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
}
```
