{"id":45197,"library":"jsonwebtoken-redis","title":"jsonwebtoken-redis","description":"jsonwebtoken-redis wraps the popular jsonwebtoken library to add Redis-backed token expiration, invalidation, and refresh capabilities. Token expiration is managed entirely by Redis keys, allowing you to invalidate tokens by removing the key, or postpone expiration via the touch command. Unlike the base jsonwebtoken library, all methods return Promises (no callbacks) and require a Redis client. Version 1.0.6 is the latest stable release, with no release cadence documented. Key differentiators: Redis-managed TTL, token destroy/touch, automatic jti generation via uuid.","status":"active","version":"1.0.6","language":"javascript","source_language":"en","source_url":"git://github.com/ayrolabs/jsonwebtoken-redis","tags":["javascript","jwt","jsonwebtoken","redis"],"install":[{"cmd":"npm install jsonwebtoken-redis","lang":"bash","label":"npm"},{"cmd":"yarn add jsonwebtoken-redis","lang":"bash","label":"yarn"},{"cmd":"pnpm add jsonwebtoken-redis","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core JWT signing, verification, and decoding. jsonwebtoken-redis delegates actual JWT operations to this library.","package":"jsonwebtoken","optional":false},{"reason":"Required Redis client (e.g., redis or ioredis) to store and manage token keys.","package":"redis","optional":false},{"reason":"Generates random jti (JWT ID) when not provided in payload. Used to create unique Redis keys.","package":"uuid","optional":false}],"imports":[{"note":"The library does not ship ES module exports. Use require() or a dynamic import with default export.","wrong":"import JwtRedis from 'jsonwebtoken-redis';","symbol":"default","correct":"const JwtRedis = require('jsonwebtoken-redis');"},{"note":"Instantiate with new. The exported default is a constructor.","wrong":"const jwtRedis = require('jsonwebtoken-redis');","symbol":"JwtRedis","correct":"const JwtRedis = require('jsonwebtoken-redis');\nconst jwtRedis = new JwtRedis(client, options);"},{"note":"sign is an instance method, not static. Must be called on a JwtRedis instance.","wrong":"JwtRedis.sign(payload, secret, options).then(...);","symbol":"sign","correct":"jwtRedis.sign(payload, secret, options).then(...);"}],"quickstart":{"code":"const redis = require('redis');\nconst client = redis.createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:6379' });\nawait client.connect();\n\nconst JwtRedis = require('jsonwebtoken-redis');\nconst jwtRedis = new JwtRedis(client, {\n  prefix: 'session:',\n  expiresKeyIn: '24 hours',\n  promiseImpl: Promise\n});\n\nconst secret = process.env.JWT_SECRET ?? 'shhhhhh';\nconst payload = { scope: 'user', userId: '1' };\n\ntry {\n  const token = await jwtRedis.sign(payload, secret, { expiresKeyIn: '1 hour' });\n  console.log('Token:', token);\n\n  const decoded = await jwtRedis.verify(token, secret);\n  console.log('Verified:', decoded);\n\n  await jwtRedis.touch(token);\n  console.log('Token touched');\n\n  await jwtRedis.destroy(token);\n  console.log('Token destroyed');\n} catch (err) {\n  console.error(err);\n} finally {\n  await client.quit();\n}","lang":"javascript","description":"Demonstrates full lifecycle: sign, verify, touch (extend TTL), and destroy (invalidate) a JWT using Redis-backed expiration."},"warnings":[{"fix":"Use only expiresKeyIn option in sign() to allow Redis-managed TTL and enable touch().","message":"If you use expiresIn or exp claim in the payload, the Redis key expiration is based on that JWT expiration, and touch() will NOT work because the token itself expires before Redis key can be extended.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use CommonJS require() or dynamic import with default export.","message":"The library does not export ES modules. Using import JwtRedis from 'jsonwebtoken-redis' will fail in Node.js with ESM.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure Redis client is connected before using jwtRedis methods. Handle connection errors.","message":"All token operations require Redis client to be connected. verify() will throw if Redis is down, even if the token is valid and not expired.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Monitor jsonwebtoken changelog and update jsonwebtoken-redis accordingly (it may lag behind).","message":"The library relies on jsonwebtoken for JWT operations, which may have breaking changes or security advisories. Always audit jsonwebtoken updates.","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'1.0.6':64 'add':13 'allow':31 'automat':83 'back':16 'base':49 'cadenc':73 'callback':57 'capabl':22 'client':62 'command':46 'destroy/touch':82 'differenti':76 'document':74 'entir':27 'expir':18,24,42 'generat':85 'invalid':19,34 'javascript':88 'jsonwebtoken':2,5,10,50,90 'jsonwebtoken-redi':1,4 'jti':84 'jwt':89 'key':30,39,75 'latest':67 'librari':11,51 'manag':26,79 'method':53 'popular':9 'postpon':41 'promis':55 'redi':3,6,15,29,61,78,91 'redis-back':14 'redis-manag':77 'refresh':21 'releas':69,72 'remov':37 'requir':59 'return':54 'stabl':68 'token':17,23,35,81 'touch':45 'ttl':80 'unlik':47 'uuid':87 'version':63 'via':43,86 'wrap':7","created_at":"2026-06-07T12:53:49.773178+00:00","updated_at":"2026-06-07T12:53:49.773178+00:00","problems":[{"fix":"const jwtRedis = new JwtRedis(client, options);\njwtRedis.sign(payload, secret, options);","cause":"Using static method on the constructor instead of an instance.","error":"TypeError: jwtRedis.sign is not a function"},{"fix":"Instantiate with new JwtRedis(client, options) before calling instance methods.","cause":"Importing as default then calling as static, or not constructing instance.","error":"Error: jwtRedis.verify is not a function"},{"fix":"await client.connect(); before using jwtRedis.","cause":"Redis client not connected when calling jwtRedis methods.","error":"Error: The client must be connected before using this method"},{"fix":"Ensure secret is a non-empty string. Use process.env.JWT_SECRET ?? 'fallback'.","cause":"Passing undefined or empty secret to sign/verify.","error":"Error: secretOrPrivateKey must have a value"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://ayro.io","github":"git://github.com/ayrolabs/jsonwebtoken-redis","docs":null,"changelog":null,"pypi":null,"npm":"jsonwebtoken-redis","openapi_spec":null,"status_page":null,"smithery":null,"categories":["security","database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}