tsndr / cloudflare-worker-jwt

A lightweight JWT implementation with ZERO dependencies for Cloudflare Workers.
MIT License
649 stars 51 forks source link

Verify Token Failing #31

Closed gautammd closed 1 year ago

gautammd commented 1 year ago

Hey, below is the function am using for issuing a token and later when I try to verify the token immediately, I get false.

I tried HS256, HS512 algorithms, same issue. surprisingly, verify works if I don't pass nbf and exp whilst issuing.

import jwt from "@tsndr/cloudflare-worker-jwt"

const issueToken = async (payload: any, secret: string) => {
    return await jwt.sign({
        ...payload,
        nbf: Math.floor(Date.now() / 1000) + (60 * 60), // Not before: Now + 1h
        exp: Math.floor(Date.now() / 1000) + (2 * (60 * 60)) // Expires: Now + 2h
    }, secret)
}

Thank you again for this library :)

tsndr commented 1 year ago

Because the token will be valid in an hour from now (see: https://github.com/tsndr/cloudflare-worker-jwt/issues/30)