How can I access user ID and meta fields in an app embed block?

Topic summary

Goal: Block purchases for certain customers based on their profile data, and determine what user information is accessible in a Shopify app embed block.

Key approach and outcome:

  • The customer ID was obtained in the app embed (theme app extension) using Liquid, Shopify’s templating language, via the customer object (e.g., customer.id).
  • JavaScript access wasn’t needed for the OP’s case. Liquid provides Shopify-specific objects for logged-in customer data (see Shopify Liquid objects docs).

Passing data from Liquid to JavaScript (if needed):

  • Define global variables on window in the Liquid block and read them in JS assets to avoid direct JS access to Shopify objects.
  • Alternatively, embed data in HTML attributes and read from the DOM. A Shopify demo (product reviews sample app) illustrates this pattern in both the Liquid block and JS asset.

Developments and status:

  • An initially accepted answer was deleted, but the OP confirmed the Liquid-based solution and marked the issue resolved.
  • No explicit confirmation about directly accessing custom meta fields in JS; solution relies on Liquid objects and optional data handoff to JS.
Summarized with AI on December 20. AI used: gpt-5.

I just got it in the Liquid code of the embedded extension. Liquid provides a bunch of Shopify specific objects for easy access (https://shopify.dev/docs/api/liquid/objects). To get the customer id we just used the liquid customer object like this: “customer.id”.

We didn’t need to get it in JavaScript.