Chord OMS
...
Gatsby
SDK Reference
useUser
8min
the useuser hook returns a series of methods for managing a shopify customer account the customer must have an active authentication session (see useauth ) for these methods to work import { useuser } from '@chordcommerce/gatsby theme performance' const { user, status, createuseraddress, loaduser, modifyuseraddress, modifyuserdefaultaddress, removeuseraddress } = useuser() user represents the current user example const { user } = useuser() status string indicating the status of the user in redux this string can be used to determine if the user has been loaded yet, which happens asynchronously after page load example import { useuser, userstatus } from '@chordcommerce/gatsby theme performance' const { status } = useuser() if (status === userstatus failed) { // the user could not be loaded, probably because there is no valid authentication session } createuseraddress() adds a new address to the shopify customer's address book example const address = { address1 '', address2 '', city '', company '', country '', firstname '', lastname '', phone '', province '', zip '' } const isdefaultaddress = false await createuseraddress(address, isdefaultaddress) loaduser() reloads the current user this is automatically called on every page load and with every other useuser method example await loaduser() modifyuseraddress() updates an address in the shopify customer's address book example const addressid = '123' const address = { address1 '', address2 '', city '', company '', country '', firstname '', lastname '', phone '', province '', zip '' } const isdefaultaddress = false await modifyuseraddress(addressid, address, isdefaultaddress) modifyuserdefaultaddress() updates which address is marked as the default address in the shopify customer's address book example const addressid = '123' await modifyuserdefaultaddress(addressid) removeuseraddress() removes an address from the shopify customer's address book example const addressid = '123' await removeuseraddress(addressid)