MeridianProvider is the one component every React integration needs. Mount it once, high in your embedded app’s tree, and everything below it can read the shop’s plan and drive billing.
What it does on mount
One request to/me fetches the shop’s CRM record, its resolved entitlements and your active plans together, so a gate check further down the tree is synchronous.
loading stays true until that request resolves, and status stays "loading" until a snapshot has loaded. Render skeletons or null while it does. Gating on an unresolved snapshot reads every feature as off and will flash the upgrade prompt at a paying merchant. If that first load fails, status turns "failed" or "rate_limited", and features stay off unless you pass failOpen. See Fail open or fail closed.
It also captures the staff member currently using your app, in a background call that never blocks your render. This needs your Shopify client id and secret in App Settings. See Automatic contact capture.
It also sends the Core Web Vitals App Bridge measured for the page, in the background, shortly after App Bridge reports them. See Web Vitals.
Props
Passing a new
shopToken switches the token every later call uses, but it does not re-read on its own. Call refresh() if you need the snapshot to follow. The handler props are read live, so inline closures are fine and never stall the provider.
Token refresh, handled for you
A shop token lasts about an hour. When a call comes back expired, the provider gets a new token, replays that one call, and updates its own state. Your component sees a slightly slower call, not an error. Where the new token comes from depends ongetShopToken.
Persist the new token from onTokenRefreshed if your app caches it. Otherwise the next server render mints a fresh one.
From your server, with getShopToken
Pass getShopToken and the provider asks your app’s server for the new token, the way App Bridge session tokens work. It never refreshes a token itself then. SDK 3.7.0 and later.
fetch sent to your app’s origin. It mints the token with mintShopToken and passes the refused one back, so your server checks again, on every renewal, that the person still has access to the store. See A token the browser was refused for the route.
The provider calls getShopToken when Meridian refuses the current token with SHOP_TOKEN_EXPIRED, SHOP_TOKEN_REVOKED, SHOP_TOKEN_REFRESH_EXPIRED or a plain 401 UNAUTHORIZED (“Invalid shop token.”), with that token and the code. Then it replays the refused call once with the token your server returns, and fires onTokenRefreshed. That covers a page left open past the 7 days a token can be refreshed, and a page left idle for more than an hour after its token was replaced, which the provider cannot heal on its own.
- On a refusal only. Your server returns the same live token until it expires, so asking ahead of expiry would change nothing.
- Once for calls refused together. They share one
getShopTokencall. A call refused with a token another call has already replaced is replayed with the new one, without asking again. If your app passes a newshopTokenwhilegetShopTokenis still pending, the provider keeps yours and replays with it. - No replay without a new token. When
getShopTokenthrows, resolvesnull, or resolves the refused token itself, the call fails with Meridian’s original refusal (on the/meload,errorshows its message), and the provider logs oneconsole.errorper mount. A replay that is refused again fails the same way, without a second call. - Not for every
401.SHOP_TOKEN_WRONG_APIandSHOPIFY_ACCESS_TOKEN_STALEkeep their own handling: see thebaseUrlprop and When the merchant has to re-authorize.
Without getShopToken
The provider rotates an expired token itself, against POST /auth/refresh, and replays the call once.
A token revoked by an uninstall (SHOP_TOKEN_REVOKED) goes through the same refresh. Once the shop has reinstalled, Meridian answers it with the install’s current token, so a page your server rendered with an old token still loads. See After an uninstall.
A refresh cannot start a new chain, so a page left open for more than 7 days shows SHOP_TOKEN_REFRESH_EXPIRED on error until the merchant reloads it. A page left idle for more than an hour after its token was replaced shows Invalid shop token. the same way. See How long a token can be refreshed.
When the merchant has to re-authorize
Meridian bills a shop by reading your app’s own Shopify offline session. If that session is gone or its refresh keeps failing, Meridian answersSHOPIFY_ACCESS_TOKEN_STALE and no retry can fix it. Only the merchant relaunching the app can.
The provider handles this once per mount, so a page with several failing calls does not reload in a loop. By default it reloads the window, which in an embedded app puts the merchant back through Shopify’s authorization. Pass onShopifyAccessTokenStale to show your own prompt instead:
Routing writes through your own server
By default the provider calls Meridian directly from the browser with the shop token. Some apps prefer billing actions to be enforced server-side. Pass an override and the provider calls your handler instead:returnUrl before handing it to you. After onUndoScheduledChange, it still sends the merchant to a confirmationUrl you return, or refreshes state when there is none. Reads and discount validation are not overridable.
Running unconfigured
mintShopToken returns null when Meridian has no credentials or is unreachable, so mount the provider conditionally and render your app without it in that case. meridian.configured tells the two apart: configured === true with a null token means Meridian failed while your loader ran, and your app decides whether paid features show. See Telling no plan from a Meridian failure. If you mount your tree without the provider, the SDK’s own page components degrade to an empty state and log one warning naming the likely cause, rather than crashing the render.
For code of your own that must survive both cases, useOptionalMeridian() returns null instead of throwing. See useMeridian.