-
Goal: I'm trying to import jsonwebtokens into retool so that I can use it to encode json data. When I try to run the code below, I get an error: "can't access lexical declaration 'registered_claims_schema' before initialization".
-
Steps:
-
I've been referencing these posts from the forum: Importing js libraries - #3 by zewen and How do I use external libraries?
-
I added the following libraries at the application level:
https://cdnjs.cloudflare.com/ajax/libs/jsonwebtoken/9.0.2/index.js
https://cdnjs.cloudflare.com/ajax/libs/jsonwebtoken/9.0.2/decode.min.js
https://cdnjs.cloudflare.com/ajax/libs/jsonwebtoken/9.0.2/sign.min.js
-
I used
Object.keys(window)
to verify that the new libraries were imported to the app. These are some of the values that show when I print to console: "jws", "validate", "validateOptions", "validatePayload".
-
I've also tried using require to require the jsonwebtoken library, but 'require' was not defined.
// Secret key for signing the JWT
const secretKey = 'your-secret-key';
// Payload data to include in the JWT
const payload = jsonValue.value;
// Options for the JWT (e.g., expiration time)
const options = {
expiresIn: '10h', // Token expires in 1 hour
};
// Create the token
var token = validatePayload(payload, secretKey, options)
console.log(token)
Thank you for your help!