redis-jwt
Management of sessions by Redis and JWT for horizontal scalability, with the possibility of having one session at a time or multiple for the same user
Requirements
Installation
Npm
npm install redis-jwt --save
Yarn
yarn add redis-jwt
Usage
; const r = //host: '/tmp/redis.sock', //unix domain host: '127.0.0.1' //can be IP or hostname port: 6379 // port maxretries: 10 //reconnect retries, default 10 //auth: '123', //optional password, if needed db: 0 //optional db selection secret: 'secret_key' // secret key for Tokens! multiple: false // single or multiple sessions by user kea: false // Enable notify-keyspace-events KEA; r;
Example Redis-jwt with Express
;;const r = ;const app = ; // Loginapp; // Meapp; // Middleware { return { const token = reqheaders'authorization'; r }} app;
Options
Sign
// Basicrthen // TTL : 50 seconds, 10 minutes, 5 hours, 3 days, 1 year ...rthen... // Save data in token : Object are saved in tokenrthen... // Save data in redis : Object are saved in redis-jwtrthen... // Example TTL + dataToken + dataSessionrthen...
Verify
// Basicr // Get data from redisr
Exec
// Execute Redis comandsconst exec = r; exec;
Call
// Method's redis-jwtconst call = r; // Test Pingcallthen // Createcallthen // exits by keycallthen // Get ttl by Keycallthen // Get values by keycallthen // Get values by Patterncallthen // Get count by Patterncallthen // Get infocallthen // Destroy by keycallthen // Destroy multiple by keycallthen
Events
// Readyr; // connectedr; // disconnectedr; // errorr;
Development
Start
npm start
Compile
npm run compile
Test
npm test
License
MIT © Leonardo Rico