acklen-keystone
Version:
Web Application Framework and Admin GUI / Content Management System built on Express.js and Mongoose
22 lines (17 loc) • 472 B
JavaScript
import decode from 'jwt-decode';
export function getTokenExpirationDate (token) {
const decoded = decode(token);
if (!decoded.exp) {
return null;
}
const date = new Date(0); // The 0 here is the key, which sets the date to the epoch
date.setUTCSeconds(decoded.exp);
return date;
}
export function isTokenExpired (token) {
const date = getTokenExpirationDate(token);
if (date === null) {
return false;
}
return !(date.valueOf() > new Date().valueOf());
}