Skip to content

Fix for lib0 issue 88: Expired JWT error #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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