Embedded pages
Your app's page inside the store admin. App Bridge tells it which store and language it's in, gives your backend a token naming who's asking, and shows toasts and moves the admin for you.
Install it
npm i @snizu/app-bridgeThe admin opens your manifest's admin_url in a frame under Apps, and adds three launch parameters to its address: store_id, host (the admin's origin, the only one your page should talk to) and locale. Connect once when the page loads:
import { createAppBridge } from "@snizu/app-bridge";
const bridge = createAppBridge();
const { storeId, locale, direction, theme } = await bridge.context;
document.documentElement.lang = locale;
document.documentElement.dir = direction;
// A token for your backend, before every request. Cached until shortly before it expires.
const response = await fetch("/api/orders", {
headers: { authorization: `Bearer ${await bridge.getSessionToken()}` },
});
bridge.toast("Saved");
bridge.toast("Couldn't reach the carrier", { tone: "error" });
bridge.navigate("/orders/ord_01k9c3m7x2v5q8n4t0d6b1w9hz");createAppBridge(options?)
hostOriginstringThe admin's origin. Thehostlaunch parameter by default.timeoutMsnumberHow long to wait for the admin to answer. 10 seconds by default.
The bridge
contextPromiseWhere the app runs:storeId,locale,direction(ltrorrtl),theme(lightordark) and the protocol'sversion.getSessionToken()Promise<string>A token for your backend. Call it before every request.toast(message, { tone })A toast in the admin.toneisinfo, the default, orerror.navigate(path)Moves the admin to a path inside this store's admin, like/orders. Anything else is refused.destroy()Stops listening to the admin.
Verify the session token
Your page runs in a browser, so trust your backend's check of the token, never the page. The token is an HS256 JWT signed with your app's client secret, valid for 60 seconds:
typsessionAn admin session token. A checkout block's token never passes as one.audstringYour app's client ID.deststore_…The store the page is open in.substringThe staff member using it.issurlThe store's Admin API address.nbf, exp, iatsecondsWhen it starts and stops being valid, and when it was made.jtistringUnique to each token, so you can refuse one used twice.
import { createHmac, timingSafeEqual } from "node:crypto";
function same(left, right) {
const a = Buffer.from(left);
const b = Buffer.from(right);
return a.length === b.length && timingSafeEqual(a, b);
}
function verifyToken(token, key, clientId, type, now) {
const [header, claims, signature] = String(token ?? "").split(".");
if (!header || !claims || !signature) return null;
const expected = createHmac("sha256", key).update(`${header}.${claims}`).digest("base64url");
if (!same(expected, signature)) return null;
let decoded;
try {
decoded = JSON.parse(Buffer.from(claims, "base64url").toString("utf8"));
} catch {
return null;
}
const inTime = decoded.nbf - 5 <= now && now <= decoded.exp + 5;
return inTime && decoded.aud === clientId && decoded.typ === type ? decoded : null;
}
export function verifySessionToken(token, secret, clientId, now = Date.now() / 1000) {
return verifyToken(token, secret, clientId, "session", now);
}It allows five seconds of difference between your clock and ours, either way.
snizu app create writes an app whose lib/verify.js does this, with tests, and a GET /api/me route that uses it.
The frame
The page runs on your own origin, in a sandboxed frame that may run scripts, submit forms, open popups and downloads, show dialogs and write to the clipboard. It can't navigate the admin itself: ask with navigate.
The protocol's own pieces, isAppMessage, isHostMessage, isAdminPath, LAUNCH_PARAMS and BRIDGE_VERSION, are exported too, for testing a page outside the admin.
Was this page helpful?
Updated 25 Nov 2026