Your app’s own console, inside Foir
An app can show its own console screens inside the Foir console: preorders, sync health, anything the app manages. It declares a full-page placement, and the console shows the page in a frame, in its navigation, like any Foir screen.
The page is on your app’s own domain, which is a different site from the console, so no cookie reaches it. The console hands the page a token instead.
What the page acts as
The token is the user looking at the page, acting through your app:
- At the level your app is installed at. An app installed in an organisation works on that organisation’s data, whoever is looking.
- With what your placement declares and this user holds, and never more. An app cannot lift a user above their own permissions. What the user does not hold is withheld, with the reason, so the page can hide or grey out what they cannot do.
- Permission by permission. A user who holds part of what you declare is given that part. If you declare the read of every model and they read orders alone, the page reads orders.
- Reading only, for a user working beneath the install. They see the app because an organisation above them installed it, and they hold nothing at its level to write with.
- For five minutes at a time, and only while they are signed in. The page asks for a fresh token before it lapses, and the token is checked again as it is used. The page’s access ends at once when the user loses a permission the token carries, when they sign out, when the app is turned off or removed, and when an update stops declaring a grant the token carries.
The token is posted into the frame, to your placement URL’s origin and nowhere else. It never goes in a URL.
Declare the placement
In your app’s manifest, a TARGET_FULL_PAGE placement lists the grants its page acts with, in the names a team member’s role is composed from:
{
"ui": {
"placements": [
{
"key": "preorders",
"target": "TARGET_FULL_PAGE",
"title": "Preorders",
"url": "https://shop-app.example/foir/preorders",
"grants": ["records:read.all:preorder", "records:write.all:preorder"]
}
]
}
}The page must be served over https. Only full pages declare grants: a sidebar or editor tab is handed its record, not a token.
What a placement may declare:
- A permission someone on a team can hold. Anything else is refused when the manifest is validated, with the reason.
- Each permission by name. A wildcard (
*,records:*) and a permission that gives others (project:manage) are refused. Installing your app is agreeing to the list, and either would grow as permissions are added later. .allfor every owner’s records.records:read:preorderis the user’s own preorders.records:read.all:preorderis every preorder.- A write beside its read. Writing does not include reading. A page that reads and changes preorders declares both.
- The read of every model the page’s queries reach. A query that follows a reference into another model reads that model too. A page that lists preorders with each one’s
edition { _id }declaresrecords:read.all:editionbesiderecords:read.all:preorder. Without it, every row that names an edition is refused, while rows that name none read as before, so a page tested on rows with the reference empty can pass and still fail on real ones.
A placement that declares scopes, as it did before October 2026, is refused, and the refusal says what to declare in their place.
The install review lists these grants, so installing your app is agreeing to them.
Connect the page
import { connectPlacement, FOIR_CONSOLE_ORIGINS } from '@foir/sdk/placement';
const session = await connectPlacement({
apiUrl: 'https://api.foir.dev',
consoleOrigins: FOIR_CONSOLE_ORIGINS.production,
});
if (!session.can('records:write.all:preorder')) hideEditControls();
const data = await session.request(`{ preorders { edges { node { _id status } } } }`);
session.onSignedOut(() => showSignedOutMessage());connectPlacement tells the console the page is ready, waits for the token, and keeps it fresh. It accepts a token only from the consoles you list. It rejects with PlacementRefused, with the console’s reason, when the user holds none of what the page acts with, or when no token arrives within ten seconds.
session.request throws PlacementRequestFailed when the answer carries any error, or its HTTP status is not a success. Its message says each distinct refusal once: a read refused on a field is refused on every row, and the message names it once. errors holds every one with its path, and status the HTTP status.
session.can answers as Foir’s API would. A grant for every model covers the same grant for one, so can('records:read.all:preorder') is true for a token that carries records:read.all.
session.grant holds what the console gave: the token, when it lapses, the organisation the page acts at, the grants it carries, and in withheldGrants each declared grant it does not carry whole, with why.
When the page needs a secret
The page runs in the browser, so it never holds a secret: another service’s API key, a store’s API token, anything that would let the person looking act beyond what Foir gives them. Keep the secret in Foir and have the page ask Foir to make the call.
The secret here is the project’s own, so this is for a placement the project declares itself, in its foir.config.ts. An app installed in other people’s projects keeps its credential in each install instead, and its operations read it on the app’s own service with appsecrets:read (see Apps).
- Store the secret as a project secret:
foir secrets put --label shop_api_token --value "$TOKEN"prints the secret’s ref, which is what the operation names. You can also declare it infoir.secrets.ts(see Secret Vault). - Write an operation that calls the service with a request template that reads the secret as
{{secret.NAME}}. Foir fills it in on its own servers when it makes the call. See Templated operations. - Declare the operation’s execute in the placement:
operations:execute:<operation key>. A person is given it only if their role holds it. - Run the operation from the page. Each operation is a mutation,
execute<Operation>, and one called withoutmode: ASYNCanswers in the same response.
// foir.config.ts
defineOperation({
key: 'plan-terms',
name: 'Read the plan terms',
endpoint: 'https://my-store.myshopify.com/admin/api/2025-07/graphql.json',
secretBindings: [{ name: 'SHOP_TOKEN', secretRef: 'sec_abc123...' }], // the ref `foir secrets put` printed
requestTemplate: {
method: 'POST',
headers: { 'X-Shopify-Access-Token': '{{secret.SHOP_TOKEN}}' },
bodyTemplate:
'{"query": "query ($n: Int!) { sellingPlanGroups(first: $n) { nodes { name } } }", "variables": {"n": {{input.first}}}}',
},
inputSchema: { type: 'object', properties: { first: { type: 'integer' } } },
outputSchema: { type: 'object', properties: { data: { type: 'object' } } },
});// The page
if (session.can('operations:execute:plan-terms')) {
const { executePlanTerms } = await session.request(
`mutation { executePlanTerms(input: { first: 20 }) { result { data } } }`,
);
}The secret’s value never reaches the browser or your app’s server. The page sees only what the operation answers. A token that does not carry the operation’s execute has no executePlanTerms mutation at all.
Match the console’s theme
The console’s theme is the user’s own setting, and need not be their system’s. A page that follows prefers-color-scheme can sit dark inside a light console. The console tells the page how it looks instead:
const session = await connectPlacement({
apiUrl: 'https://api.foir.dev',
consoleOrigins: FOIR_CONSOLE_ORIGINS.production,
onAppearance: ({ theme }) => {
document.documentElement.dataset.theme = theme; // 'light' or 'dark'
},
});onAppearance is called as soon as the console says, which is before the token arrives, and again whenever the user changes their theme, so the page follows without a reload. session.appearance holds the current one.
Style the page from that attribute, and keep the system’s preference as the starting point: outside the console, nothing calls onAppearance.
Allow the console to show the page
The browser shows the page blank, however well it is authenticated, unless the page allows the console as a frame ancestor. Hydrogen, and many other frameworks, send frame-ancestors 'none' by default.
Send this header on every response the page serves:
import { placementFrameAncestors, FOIR_CONSOLE_ORIGINS } from '@foir/sdk/placement';
response.headers.set(
'Content-Security-Policy',
placementFrameAncestors(FOIR_CONSOLE_ORIGINS.production),
);A project that serves the console on its own console domain needs that origin too. The install preview lists every origin your project needs, and so does the console when a page does not connect.
Outside the console
The same page can run on its own, outside Foir. There it signs the user in with hosted sign-in, and holds the same kind of token. Your app’s background work (webhooks, syncs, scheduled runs) keeps using the app’s own install credentials; the page’s token never reaches it.