Vue Storefront is now Alokai! Learn More
GetCustomer

GetCustomer

Implements GetCustomer Unified Method.

Source

import { defineApi } from "@vsf-enterprise/unified-api-bigcommerce";
import { getNormalizers } from "@vsf-enterprise/unified-api-bigcommerce/udl";

export const getCustomer = defineApi.getCustomer(async (context) => {
  const { normalizeCustomer } = getNormalizers(context);

  try {
    const {
      data: { 0: user },
    } = await context.api.getCustomers({});

    return {
      customer: normalizeCustomer(user!),
    };
  } catch {
    return {
      customer: null,
    };
  }
});