Store

Easy way to access Store Details from Shopify in Superfans SDK.

Description

The store variable provides access to core Shopify store identifiers within the Superfans SDK.
It is primarily used for storefront requests, analytics, or debugging. This data is global and available throughout the app session.

store.accessToken is not a fixed value for the whole session. Native refreshes it when the shopper logs in or logs out. Re-read Superfans.variables.store inside Superfans.listeners.onLoginStatusChanged. Do not keep a cached token from page load.

Properties

Store variables are unique to each store.

PropertyTypeScopeDescriptionExample
store.idStringGlobalUnique ID of the store.store_id
store.accessTokenStringGlobalStorefront access token used for authorized Shopify requests. Updates when login status changes. Re-read it inside Login Status Change.storefront_access_token
store.domainStringGlobalThe Shopify domain ending with myshopify.com.your-store.myshopify.com
store.selectedLanguageCodeStringGlobalThe selected language code.en
store.selectedRegionCodeStringGlobalThe selected region code.US

Example Usage

const store = Superfans.variables.store;

if (store) {
  console.log(`Store ID: ${store.id}`);
  console.log(`Domain: ${store.domain}`);
}

Superfans.listeners.onLoginStatusChanged(() => {
  const store = Superfans.variables.store;
  const customer = Superfans.variables.customer;
  const accessToken = store?.accessToken;

  if (customer?.id) {
    console.log("Logged in. Use the updated store.accessToken.");
  } else {
    console.log("Logged out. Use the updated store.accessToken.");
  }
});

Best Practices

  1. Re-read the token after login or logout: Inside Superfans.listeners.onLoginStatusChanged, read Superfans.variables.store.accessToken again. Do not reuse a token captured earlier.
  2. Keep tokens out of the UI: Never show accessToken in the block, and do not log the full token in production.
  3. Read-only from block code: Do not write to store. Native updates accessToken when auth changes.
  4. Global availability: store is available on PDP, PLP, cart, and other screens. Still re-read it after login status changes.

Caveats

  1. Token refresh: store.accessToken changes on login and logout. The listener callback does not receive the token as an argument. Read it from Superfans.variables.store after the event has been merged.
  2. Do not hardcode access tokens. They are tied to the current shopper session as well as the store.
  3. Always follow your organization’s security policies for using access tokens.

Did this page help you?