---
title: Customer account
description: >-
  The authenticate.public.customerAccount function ensures that customer account
  extension requests are coming from Shopify, and returns helpers to respond
  with the correct headers.
api_version: v1
source_url:
  html: >-
    https://shopify.dev/docs/api/shopify-app-react-router/latest/authenticate/public/customer-account
  md: >-
    https://shopify.dev/docs/api/shopify-app-react-router/latest/authenticate/public/customer-account.md
---

# Customer account

The `authenticate.public.customerAccount` function ensures that customer account extension requests are coming from Shopify, and returns helpers to respond with the correct headers.

## authenticate.​public.​customer​Account(**[request](#authenticatepubliccustomeraccount-propertydetail-request)**​,**[options](#authenticatepubliccustomeraccount-propertydetail-options)**​)

Authenticates requests coming from Shopify customer account extensions.

### Parameters

* **request**

  **Request**

  **required**

* **options**

  **AuthenticateCustomerAccountOptions**

### Returns

* **Promise\<CustomerAccountContext>**

### AuthenticateCustomerAccountOptions

* corsHeaders

  ```ts
  string[]
  ```

### CustomerAccountContext

Authenticated Context for a customer account extension request

* cors

  A function that ensures the CORS headers are set correctly for the response.

  ```ts
  EnsureCORSFunction
  ```

* sessionToken

  The decoded and validated session token for the request Refer to the OAuth docs for the \[session token payload]\(https://shopify.dev/docs/apps/auth/oauth/session-tokens#payload).

  ```ts
  unknown
  ```

### EnsureCORSFunction



Examples

### Examples

* #### Authenticate and return offers for the customer

  ##### Description

  Authenticate and return offers for the customer

  ##### /app/routes/\*\*.ts

  ```ts
  import type {ActionFunctionArgs, LoaderFunctionArgs} from 'react-router';

  import {authenticate} from '../shopify.server';
  import {getOffers} from '../offers.server';

  // The loader responds to preflight requests from Shopify
  export const loader = async ({request}: LoaderFunctionArgs) => {
    await authenticate.public.customerAccount(request);
  };

  export const action = async ({request}: ActionFunctionArgs) => {
    const {cors, sessionToken} = await authenticate.public.customerAccount(request);

    // Get offers for the customer
    const offers = getOffers(sessionToken.des, sessionToken.sub);
    return cors({offers});
  };
  ```

  ##### /app/offers.server.ts

  ```ts
  // Most apps would load this from their database
  export function getOffers(shop: string, customerID: string) {
    const offers: Record<string, any[]> = {
      'shop.com': [
        {
          id: '1',
          title: '10% off',
          price: 10,
          type: 'percentage',
          customerId: 'gid://shopify/Customer/1001',
        },
        {
          id: '2',
          title: 'Free shipping',
          price: 0,
          type: 'shipping',
          customerId: 'gid://shopify/Customer/1001',
        },
        {
          id: '3',
          title: '5% off',
          price: 5,
          type: 'percentage',
          customerId: 'gid://shopify/Customer/1001',
        },
      ],
    };

    const allOffers = offers[shop] || [];
    // Filter offers to include only those that match the customerId
    const filteredOffers = allOffers.filter(
      (offer) => offer.customerId === customerID,
    );

    return filteredOffers;
  }
  ```

* ####

  ##### Description

  Use the \`cors\` helper to ensure your app can respond to customer account extension requests.

  ##### app/routes/public/my-route.ts

  ```ts
  import { LoaderFunctionArgs, json } from "react-router";
  import { authenticate } from "../shopify.server";
  import { getMyAppData } from "~/db/model.server";

  export const loader = async ({ request }: LoaderFunctionArgs) => {
    const { sessionToken, cors } = await authenticate.public.customerAccount(
      request,
      { corsHeaders: ["X-My-Custom-Header"] }
    );
    const data = await getMyAppData({shop: sessionToken.dest});
    return cors(data));
  };
  ```

* ####

  ##### Description

  Get store-specific data using the \`sessionToken\` object.

  ##### app/routes/public/my-route.ts

  ```ts
  import { LoaderFunctionArgs, json } from "react-router";
  import { authenticate } from "../shopify.server";
  import { getMyAppData } from "~/db/model.server";

  export const loader = async ({ request }: LoaderFunctionArgs) => {
    const { sessionToken } = await authenticate.public.customerAccount(
      request
    );
    return (await getMyAppData({shop: sessionToken.dest}));
  };
  ```

***

## Related

[Customer account UI extensions API for interacting with session tokens. - Session token API](https://shopify.dev/docs/api/customer-account-ui-extensions/latest/target-apis/platform-apis/session-token-api)

***
