Helpers and hooks for integrating LiveView with Shopifex.
Note that LiveView session keys are "shop_url" and "session_token"
(in Shopifex 2.x the key was "current_shop").
Summary
Functions
LiveView on_mount hooks for Shopify apps.
Get options that should be passed to live_session.
Return a map of session values to include in the liveview session. This will be merged with other session values and available in the on_mount.
Functions
LiveView on_mount hooks for Shopify apps.
:assign_shop_to_socket (default)
Assigns current_shop and session_token from session to socket assigns.
Use with the standard shopifex_live_session macro.
:embedded
Simplified hook for embedded Shopify apps where third-party cookies are
blocked. Reads the shop from the session (set during the HTTP request by
put_shop_in_session/1) and does NOT require tokens in URLs or LiveSocket
connect params. Redirects to /auth (respecting path_prefix) if no shop is found.
How it works
- HTTP request arrives with
id_tokenfrom App Bridge ManagedInstallplug validates the token and builds a Shopifex sessionput_shop_in_session/1serializes the shop's URL (not the struct) into the LiveView session- This hook reloads the shop from the session's
shop_urlserver-side — no tokens needed
Within a live_session, LiveView preserves the session across navigations.
Full page loads get a fresh id_token from App Bridge automatically.
Usage
live_session :my_app,
on_mount: [{ShopifexWeb.LiveSession, :embedded}],
session: {ShopifexWeb.LiveSession, :put_shop_in_session, []}
Get options that should be passed to live_session.
This is useful for integrating with other tools that require a custom live_session,
like beacon_live_admin. For example:
beacon_live_admin ShopifexWeb.LiveSession.opts(...beacon_opts) do
...
end
Return a map of session values to include in the liveview session. This will be merged with other session values and available in the on_mount.
Only the shop's URL is serialized (not the shop struct) — the LiveView session
is signed but not encrypted, so it is readable client-side; storing the
struct would leak access_token / refresh_token. on_mount reloads the shop
from the URL server-side.