useCustomer

Returns the full customer object when a user is logged in, and null when not.

Any .jsx file
import { useCustomer } from '@backpackjs/storefront';

const YourUserNameComp = () => {
  const customer = useCustomer();
  
  return (
    customer
      ? <h3>Hi, {customer.firstName}</h3>
      : <h3>Hi, guest</h3>
  )
}
Example customer object
// Logged in user
{
  "id": "Z2lkOi8vc2h...",
  "firstName": "Jane",
  "lastName": "Doe",
  "acceptsMarketing": false,
  "email": "jane.doe@packdigital.com",
  "tags": [],
  "defaultAddress": {
    ...default customer address
  },
  "addresses": [
    ...all customer addresses
  ],
  "orders": [
    ...all customer orders
  ]
  "__typename": "Customer"
}

// Logged out user
null

Last updated