JSPM

jwt-check-time

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q9953F
  • License ISC

des

Package Exports

  • jwt-check-time

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jwt-check-time) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

jwt-check-time

Simple JWT Decoder
This function can determine if the token expiration time & custom time(for reissue tokens) have been exceeded.

How to use

import checkJWT from 'jwt-check-time'

const [isNotExpired, isNotOverTime] = checkJWT
      .create({ time: '10m' }) // set config value
      .check(jwt)

Return value

  1. isNotExpired
    Check if the token exp time is overed than Date now.
  2. isNotOverTime
    Check if the time to reissue the refresh token has overed.
    Criteria time is (token's exp - config time)

Config Object Property

// This is the default config value that used if you don't set value
const defaultConfig: config = {
  time: '5m', //  number + unit
  expUnit: 's', // JWT standard time units is second
                // You can set token's time units as  s | m | h | d (regardless of case)
  expName: 'exp', // JWT standard's Expiration Time property name is "exp"
                  // You can customize it to fit your token.
};

Set Default Config

import checkJWT from 'jwt-check-time'

checkJwt.defaultConfig.time = "5m"
// or 
checkJwt.setConfig = { time: "5m", expUnit: "M" }

// ... in any file
checkJwt.check(jwt) // You can overwrite config with create method

The config of create method takes precedence.
The above setting way affects globally.