jwt-check-time
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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.

Dependents (0)

Package Sidebar

Install

npm i jwt-check-time

Weekly Downloads

1

Version

0.1.0

License

ISC

Unpacked Size

5.93 kB

Total Files

4

Last publish

Collaborators

  • aio39