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.
| Property | Type | Scope | Description | Example |
|---|---|---|---|---|
store.id | String | Global | Unique ID of the store. | store_id |
store.accessToken | String | Global | Storefront access token used for authorized Shopify requests. Updates when login status changes. Re-read it inside Login Status Change. | storefront_access_token |
store.domain | String | Global | The Shopify domain ending with myshopify.com. | your-store.myshopify.com |
store.selectedLanguageCode | String | Global | The selected language code. | en |
store.selectedRegionCode | String | Global | The 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
- Re-read the token after login or logout: Inside
Superfans.listeners.onLoginStatusChanged, readSuperfans.variables.store.accessTokenagain. Do not reuse a token captured earlier. - Keep tokens out of the UI: Never show
accessTokenin the block, and do not log the full token in production. - Read-only from block code: Do not write to
store. Native updatesaccessTokenwhen auth changes. - Global availability:
storeis available on PDP, PLP, cart, and other screens. Still re-read it after login status changes.
Caveats
- Token refresh:
store.accessTokenchanges on login and logout. The listener callback does not receive the token as an argument. Read it fromSuperfans.variables.storeafter the event has been merged. - Do not hardcode access tokens. They are tied to the current shopper session as well as the store.
- Always follow your organization’s security policies for using access tokens.
Updated 23 days ago
Did this page help you?