Vue Storefront is now Alokai! Learn More
GetCustomer

GetCustomer

Implements GetCustomer Unified Method.

Source

import { defineApi } from "@vsf-enterprise/unified-api-sapcc";
import { getNormalizers } from "@vue-storefront/unified-data-model";
import "./extended.d";

export const getCustomer = defineApi.getCustomer(async (context) => {
  try {
    const user = await context.api.getUser({});
    const { normalizeCustomer } = getNormalizers(context);

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