UNPKG

@absolute/change-tracker-node-sdk

Version:

ChangeTracker SDK for Node.js

19 lines (14 loc) 603 B
const jwt = require('jsonwebtoken'); /** * generateToken - create a jwtToken * @param {string} secret - the secret to crypt the token * @param {string} tableName - the name of the accessed table * @param {string} [rowKey] - the key of the accessed record * @param {number} [duration=5] - the token duration in minutes **/ function generateToken(secret, tableName, rowKey, duration = 5) { const claims = {table: tableName}; if (rowKey) claims.key = rowKey; return jwt.sign(claims, secret, {expiresIn: duration * 60}, undefined); } module.exports = {generateToken}