diff --git a/crypto/jwt.js b/crypto/jwt.js index cbcc33d..f0b8e83 100644 --- a/crypto/jwt.js +++ b/crypto/jwt.js @@ -47,7 +47,7 @@ export const verifyJwt = async (publicKey, jwt) => { throw new Error('Invalid JWT') } const payload = _parse(payloadBase64) - if (payload.exp != null && time.getUnixTime() > payload.exp) { + if (payload.exp != null && time.getUnixTimeInSeconds() > payload.exp) { throw new Error('Expired JWT') } return { diff --git a/time.js b/time.js index 07965c6..8775cc9 100644 --- a/time.js +++ b/time.js @@ -21,6 +21,13 @@ export const getDate = () => new Date() */ export const getUnixTime = Date.now +/** + * Return current Unix time in seconds (since epoch). + * + * @return {number} current Unix time in seconds + */ +export const getUnixTimeInSeconds = () => Math.floor(Date.now() / 1000) + /** * Transform time (in ms) to a human readable format. E.g. 1100 => 1.1s. 60s => 1min. .001 => 10μs. *