Skip to content

The editor login bridge

The editor and the home site are different origins (studio.patternyard.dev vs patternyard.dev), so the editor cannot read the home site’s session directly. To show the signed-in username, it uses a small cross-origin login bridge built on postMessage.

The editor embeds a hidden 100×100 iframe pointed at the home site’s /embed/editor route, passing its own origin as the external query parameter. That route reads the home session and posts the identity back to the editor.

Diagram
SideResponsibility
Editor (src/containers/home-communication.jsx in patternyard-studio)Mounts the hidden iframe at ${PM_HOME_ROOT}/embed/editor?external=<editorOrigin> and listens for a message of shape { type: "login", packet: { loggedIn: true, username } }.
Home (src/routes/embed/editor/+page.svelte in PatternYard-Home)Client-only route (prerender = false, ssr = false). Validates the external origin, reads identity from $lib/stores/session.js, and posts the packet only to that exact origin (never "*").