Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crypto/jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down