jsonwebtokenify
Description
jsonwebtokenify
is a library that allows the generation, verification, and decoding of JWTs (JSON Web Tokens). The library provides flexibility in customizing the payload of the token, and provides methods to verify the validity of the token and decode the payload.
Installation
To install the library, you can use npm:
npm install jsonwebtokenify
Usage
First, you need to import the JWT
class from the library:
import { JWT } from "jsonwebtokenify";
Next, you can instantiate a JWT object by providing a "secret", which will be used to sign your tokens:
const jwt = new JWT('your_secret');
To generate a new JWT token, you can use the generate method. This method takes a payload object and an optional options object:
const payload = { id: '123', name: 'Test User' };
const options = { expiresIn: '1h' }; // Options for the token generation
const token = jwt.generate(payload, options);
To verify a token, use the verify method. This method takes the token and the secret used to sign it and returns a boolean indicating whether the token is valid:
const isValid = jwt.verify(token, 'your_secret');
Finally, to decode a token's payload without verifying it, you can use the decode method:
const decodedPayload = jwt.decode(token);
Tests
To run the tests for the library, you can use the npm test command:
npm test
Contributions
Contributions to jsonwebtokenify are welcome. Please ensure you follow code and testing conventions before making a pull request.
License
This project is licensed under the terms of the MIT license. See the LICENSE file for details.