Skip to content

Instantly share code, notes, and snippets.

@CerealKiller97
Created October 30, 2019 15:23
Show Gist options
  • Save CerealKiller97/ee6e0df58290d39f86068e84c19f6adf to your computer and use it in GitHub Desktop.
Save CerealKiller97/ee6e0df58290d39f86068e84c19f6adf to your computer and use it in GitHub Desktop.
JWT library
/**
* @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