1.1.7 • Published 1 year ago
jwt-promisify v1.1.7
Table of contents
About
jwt-promisify
is a wrapper for jsonwebtoken
with support for Promises and TypeScript.
Installation
Install this package using NPM:
npm install jwt-promisify --save
Usage
import jwt from "jwt-promisify";
Or using CommonJS:
const jwt = require("jwt-promisify");
API Documentation
jwt.decode(token)
Decodes a token without verifying the signature. Returns null
if the token cannot be decoded.
Parameter | Type | Optional | Description |
---|---|---|---|
token | string | ❌ | A signed token. |
options | DecodeOptions | ✔ | Options for decoding. |
Warning This method does not verify the signature. You should not use this method to decode untrusted tokens. You most likely want to use
jwt.verify()
instead.
jwt.sign(payload, key, options)
Signs a payload and generates a token.
Parameter | Type | Optional | Description |
---|---|---|---|
payload | string , object , Buffer | ❌ | Token payload. |
key | Key | ❌ | Secret key. |
options | SignOptions | ✔ | Options for signing. |
jwt.verify(token, key, options)
Verifies and decodes a given token.
Parameter | Type | Optional | Description |
---|---|---|---|
token | string | ❌ | A signed token. |
key | Key | ❌ | Secret key. |
options | VerifyOptions | ✔ | Options for signing. |
Key
A secret key used for signing and verifying tokens. Can be one of the following:
string
Buffer
{ key: string; passphrase: string; }
Resources
Acknowledgements
- TypeScript definitions adapted from
@types/jsonwebtoken
License
This project is licensed under MIT.