jwt-knex
This library completely repeats the entire functionality of the library jsonwebtoken, with one important addition. jwt-knex allows you to store the token label in database with knex to verify validity. The absence of a token label in redis makes the token not valid. To destroy the token in jwt-knex, there is a destroy method. This makes it possible to make a token not valid until it expires.
The package is tested with oracledb but should be working just when passing an instance of knex in.
This package is inspired by jwt-redis
Installation
npm install jwt-knex
Support
This library is implemented as a part of other project and might contains bugs. Please create an issue on github, any contribution are welcomed.
Quick start
-
Create and run the migration script with knex to create the required table
knex migrate:make add_jwt_tablesEnter the following code to create the table. Make sure you add
JWT_ORACLE_TABLE_NAME
to your environment variables:exportsknexschema;exportsknexschema;Run the migration script with knex.
knex migrate:latest -
Added the jwt-knex package as in below:
const knex = knexConfig;const JwtKnex = ;const secretOrPrivateKey = "secret";const jwt =knexsecretOrPrivateKeytableName: processenvJWT_ORACLE_TABLE_NAME;const payload =sub: "1234567890"name: "John Doe"admin: truejti: "jti";jwt;
// TODO: documenting the APIs
Contribution
- Clone this repo
- Start the docker composedocker-compose up
- Migrate the databasenpm run knex -- migrate:latest
- Run testsnpm t