Chord OMS
...
Next.js
SDK Reference

useUser

10min

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

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:

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:

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:

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:

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:



Updated 03 Mar 2023
Did this page help you?