The Vue Storefront Essentials Course is now available! Learn More
GetCustomer

GetCustomer

Implements GetCustomer Unified Method.

Source

import { defineApi, getCurrentCustomer } from "@vsf-enterprise/unified-api-commercetools";
import { getNormalizers } from "@vue-storefront/unified-data-model";

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

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