Skip to content

Commit

Permalink
remove math abs
Browse files Browse the repository at this point in the history
  • Loading branch information
tsndr committed Mar 1, 2024
1 parent 5942b3d commit c75c260
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ export async function verify(token: string, secret: string | JsonWebKey | Crypto

const now = Math.floor(Date.now() / 1000)

if (payload.nbf && payload.nbf > now && Math.abs(payload.nbf - now) > (options.clockTolerance ?? 0))
if (payload.nbf && payload.nbf > now && (payload.nbf - now) > (options.clockTolerance ?? 0))
throw new Error("NOT_YET_VALID")

if (payload.exp && payload.exp <= now && Math.abs(payload.exp - now) > (options.clockTolerance ?? 0))
if (payload.exp && payload.exp <= now && (now - payload.exp) > (options.clockTolerance ?? 0))
throw new Error("EXPIRED")

const key = secret instanceof CryptoKey ? secret : await importKey(secret, algorithm, ["verify"])
Expand Down

0 comments on commit c75c260

Please sign in to comment.