A Next.js demo application that helps you learn how to embed and work with the Custom Canvas feature. It renders a tokenized <em-beddable> component, lets you switch themes, manage per-user permissions (write/read-only/no access), and simulate multiple dashboards whose state lives in session storage.
- The sidebar lists sample dashboards (stored in session storage). You can add, rename, delete, and filter them by user access.
- Selecting a dashboard calls
app/api/token/route.ts, which exchangescustomCanvasState, user email, and permission flags for a short-lived security token using your platform API. - The embeddable web component is injected via
NEXT_PUBLIC_EMBEDDABLE_SCRIPT_URLand mounted with the token plus optional client context (theme). - Permissions drive whether the selected dashboard is writable, read-only, or hidden for the current user.
- Theme selections are saved in session storage and passed as
client-contextto the<embeddable>tag.
- Node.js 20+ (Next.js 16)
- npm (or pnpm/yarn/bun)
Create .env.local with your platform values:
EMBEDDABLE_API_KEY= # server-side key used by /api/token
EMBEDDABLE_ID= # embeddable identifier
NEXT_PUBLIC_EMBEDDABLE_API_URL= # base API URL hit by /api/token
NEXT_PUBLIC_EMBEDDABLE_BASE_URL= # base URL passed to <em-beddable>
NEXT_PUBLIC_EMBEDDABLE_SCRIPT_URL= # script that defines <em-beddable>
# Optional niceties
NEXT_PUBLIC_USER_EMAIL=
NEXT_PUBLIC_CONTACT_EMAIL=
NEXT_PUBLIC_GITHUB_REPOSITORY_URL=
NEXT_PUBLIC_DOCUMENTATION_URL=
npm ci
npm run dev
# open http://localhost:3000app/page.tsx– layout and wiring between header, sidebar, and embeddable.app/components/Embeddable.tsx– mounts<em-beddable>with token + client context and handles loading states.app/api/token/route.ts– server route that exchanges dashboard state + user + permissions for a security token.app/components/PermissionsModal.tsx– per-user access controls (write/read-only/no access).app/lib/dashboardUtils.ts– dashboard creation, storage, filtering, and theme persistence helpers.utils/constants.ts– env config, sample users, navigation items, and help links.
- Pick a user in the header; dashboards filter to what they can access.
- Select a dashboard; a token is requested and the embeddable renders.
- Use the theme dropdown to switch themes; the embeddable receives the updated theme via
client-context. - Open the menu on a dashboard to edit permissions, rename, or delete.
- Add a dashboard to see how new
customCanvasStatevalues are handled end-to-end.
- Update sample users/navigation in
utils/constants.ts. - Tweak initial dashboards or permission defaults in
app/lib/dashboardUtils.ts. - Style tokens and component classes in
app/lib/tokens.tsandapp/globals.css. - Replace help links (Docs/GitHub/Contact) via the env vars in
utils/constants.ts.
- The
/api/tokenroute keepsEMBEDDABLE_API_KEYserver-side; never expose it to the client. - Tokens expire after
TOKEN_EXPIRY_SECONDS(7 days by default); adjust inutils/constants.ts. - Serve the embeddable script over HTTPS in production.