Created
October 30, 2019 15:23
-
-
Save CerealKiller97/ee6e0df58290d39f86068e84c19f6adf to your computer and use it in GitHub Desktop.
JWT library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @description Checks if JWT Token has expired | |
* @param {string} token | |
* | |
* @return {boolean} | |
*/ | |
const isTokenExpired = token => { | |
/** @type {string[]} */ | |
const parts = token.split("."); | |
/** @type {number} */ | |
const { exp } = JSON.parse(atob(parts[1])); | |
if (exp === undefined) { | |
throw Error("No exp flag."); | |
} | |
/** @type {number} */ | |
const currentTime = Date.now() / 1000; | |
return currentTime > exp; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment