Skip to content

aio39/jwt-check-time

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published