Socket
Book a DemoInstallSign in
Socket

jwt-cache

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jwt-cache

Cache an async function for generating a JSON Web Token

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

jwt-cache

Cache an async function for generating a JSON Web Token

Rolling Versions

Installation

yarn add jwt-cache

Usage

import jwtCache from 'jwt-cache';

const cache = jwtCache({
  getToken: async () => {
    // this could be slow code for generating a JSON Web Token
    // with an expiry represented via the standard "exp" value
    return sign({hello: 'world'}, `my_secret`, {expiresIn: 3});
  },
  // If the token will not be valid for this many ms, get
  // a new token rather than returning the cached token
  // Defaults to 1 second
  minimumValidityMilliseconds: 100,
  // Optionally eagerly fetch a token before it is needed.
  // This will trigger fetching a new token this many ms
  // before it would reach the minimum validity threshold
  eagerRefreshMilliseconds: 100,
});

// When you need a token:
cache.getToken().then((token) => {
  // use the token here
});

FAQs

Package last updated on 16 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts