Generate JWT token in js

we're trying to embed our metabase analytics into a retool iframe. We have a node.js code to generate the url. this code works if it runs in node.

var jwt = require("jsonwebtoken");

var METABASE_SECRET_KEY = "our_key";

var payload = {
  resource: { dashboard: 2 },
  params: {},
  exp: Math.round( / 1000) + (10 * 60) // 10 minute expiration
var token = jwt.sign(payload, METABASE_SECRET_KEY);

var iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true&titled=true";
return iframeUrl;

we tried loading the jsonwebtoken using the app script loader but i think it fails because it has require commands inside it. How can we sign a JWT token to be able to use that in our embed frame. The only documentation we found was regarding JWT custom auth for REST API and not in js

thanks for the help!

Hey @joe_fl!

It looks like the jose library supports JWT signing and has a UMD build. Could that work?

that works thanks, is there a generic answer to these kind of scenarios? What happens if i need to use a library that doesn't support umd builds?

I'm not aware of much support for non-UMD libraries since scripts need to be able to work in the browser :confused: There is this guide that goes over how you can create your own custom component using any npm package but it does require you to do some of the hosting yourself.