Skip to main content

Example Apps

The embedding examples are one small app built four times, in Next.js, SvelteKit, Django and Rails. Each one is the Partner Hub of Kettle & Beancounter, a fictional coffee roaster: a wholesale partner signs in and sees a Cluvio dashboard with their own spend, orders and invoices, and nobody else's. Try one, then read the version in the stack you build with, or copy it as the starting point for your own embedding. The code is MIT licensed.

StackLiveSigns the sharing secret inSource
Next.jsnextjs.embed-demo.cluvio.coma route handlerapps/nextjs
SvelteKitsveltekit.embed-demo.cluvio.coma +server.ts endpointapps/sveltekit
Djangodjango.embed-demo.cluvio.coma view, with PyJWTapps/django
Railsrails.embed-demo.cluvio.coma controller, with ruby-jwtapps/rails

The sign-in has no passwords: pick a partner, one per country, and switch between them to see the same dashboard show other rows.

All four do the same things, each in its framework's own way:

  • The server signs the sharing secret, with the partner taken from the app's own session, never from the request, in fixed_parameters. See Limiting filter values.
  • The page embeds the dashboard with @cluvio/embed, which renews the sharing secret before it expires and sizes the iframe. Next.js and SvelteKit install it from npm; Django and Rails load it as a static ES module, with no build step.
  • The page's own controls change the dashboard's filters, with changeParameters, and follow the filter bar back through parametersChanged.
  • The dashboard follows the app's language. A partner in Lisbon sees it in Portuguese, with Portuguese number and date formats and their currency.
  • Some reports are hidden per partner. A partner invoiced through its head office gets the invoice reports listed in hidden_reports.

Beside the dashboard, each app shows the decoded sharing secret with a countdown to its renewal, the server code that signed it, read from the app's own source, and every message passed between the page and the iframe. Each app's README walks through building it from an empty project of that framework.

To build your own from one of the apps, start from the one in your stack and keep its token endpoint and browser code. What changes is yours:

  • The session. Your own sign-in replaces the partner picker.
  • The filter. Your dashboards filter on the variable that says which of your customers a row belongs to, and the app fixes it in fixed_parameters in place of kettle_partner.
  • The dashboards. A sharing link to each, with Require Sharing Secret turned on, and Allow User to Change Filters too if your page changes their filters. The app signs with your organization's Embed Secret.

The app's .env.example lists the variables it reads.