import { sign } from 'jsonwebtoken';
// generate a JSON Web Token (JWT) to securely identify the user to Herald
function heraldToken(
userId: string, // user id from your database (as known to Herald)
apiKeyId: string, // API key ID from the Herald webapp
secret: string // API key secret from the Herald webapp
) {
return (
'ct_' +
sign(
{
remoteId: userId
},
secret,
{
expiresIn: 60 * 60, // JWT expires in an hour
issuer: apiKeyId
}
)
);
}