HomeDocsDeveloperNode.js and Next.js
Developer
Node.js and Next.js
Mint Reqio HS256 identity tokens on a Node.js or Next.js server using the jose library.
The snippet below is exactly what the dashboard generates under Project > Settings > Identity when you choose Next.js or Node.js. Copy it from the dashboard to get your real project ID and audience URL pre-filled.
Before you start
- A Reqio project
- A signing secret generated at Project > Settings > Identity
Install jose
Install
npm install joseMint a token
// npm install jose import { SignJWT } from "jose"; const secret = new TextEncoder().encode(process.env.REQIO_SECRET!); const now = Math.floor(Date.now() / 1000); const token = await new SignJWT({ sub: user.id, email: user.email, traits: { // amount in cents; interval is "month" | "year" plan: user.plan, amount: user.planAmount, interval: user.billingInterval, // optional CRM enrichment: 0-100 health, CRM account id, ISO renewal date healthScore: account.healthScore, accountId: account.crmId, renewalAt: account.renewalAt, }, }) .setProtectedHeader({ alg: "HS256" }) .setAudience("https://reqio.app/p/YOUR_PROJECT_ID") .setIssuedAt(now) .setExpirationTime(now + 300) .sign(secret);// npm install jose const { SignJWT } = require("jose"); const secret = new TextEncoder().encode(process.env.REQIO_SECRET); const now = Math.floor(Date.now() / 1000); const token = await new SignJWT({ sub: user.id, email: user.email, traits: { // amount in cents; interval is "month" | "year" plan: user.plan, amount: user.planAmount, interval: user.billingInterval, // optional CRM enrichment: 0-100 health, CRM account id, ISO renewal date healthScore: account.healthScore, accountId: account.crmId, renewalAt: account.renewalAt, }, }) .setProtectedHeader({ alg: "HS256" }) .setAudience("https://reqio.app/p/YOUR_PROJECT_ID") .setIssuedAt(now) .setExpirationTime(now + 300) .sign(secret);Replace
YOUR_PROJECT_IDwith your project ID, or copy the full snippet from the dashboard where the audience URL is pre-filled.Set the environment variable
Set
REQIO_SECRETto the signing secret from Project > Settings > Identity > Reveal secret. Store it server-side only; never expose it to the browser.Environment variable
REQIO_SECRET=your-signing-secretPass the token to the widget
For server-rendered pages, pass the token inline on the script tag so no client fetch is needed:
<script src="https://reqio.app/widget.js" data-project-id="YOUR_PROJECT_ID" data-identity-token="<your minted token>" async ></script>For SPAs where the user authenticates after the initial page load, call
window.Reqio.identify()after login:window.Reqio.identify(token);
Traits reference
planstring"pro".amountnumberinterval"month" | "year"amount.CRM enrichment
healthScorenumberaccountIdstringaccountId fallback).renewalAtstring (ISO 8601 date)Security
REQIO_SECRET is the symmetric key for all tokens in your project. Exposure would allow anyone to mint arbitrary identity tokens. Tokens are short-lived (300 seconds) and audience-bound to one project URL, so a leaked token cannot be replayed against a different project.