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 import { useuser } from ' /hooks/actions' const { user, status, createuseraddress, loaduser, modifyuseraddress, modifyuserdefaultaddress, removeuseraddress } = useuser() 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 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) 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 import { useuser } from ' /hooks/actions' const { loaduser } = useuser() await loaduser() 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 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) 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 import { useuser } from ' /hooks/actions' const { modifyuserdefaultaddress } = useuser() const addressid = '123' await modifyuserdefaultaddress(addressid) 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 import { useuser } from ' /hooks/actions' const { removeuseraddress } = useuser() const addressid = '123' await removeuseraddress(addressid)