Closed POD666 closed 2 years ago
Hey, you're not the first person asking me about this, but I didn't want to introduce breaking changes so I didn't implement it yet.
I think, adding an optional flag (false by default) wouldn't introduce breaking changes and could level up the developer experience for sure.
jwt.verify(token, SECRET) // returns boolean. "throwError" flag set as false by default
jwt.verify(token, SECRET, { throwError: true }) // returns true or throws an error (data type still the same)
I can raise a PR if you're happy with that.
https://github.com/tsndr/cloudflare-worker-jwt/tree/v1.2.0
We happy now? 😉
Awesome!
Maybe readme could be a bit improved:
I know, feel free to make a PR if you like to clean up the readme, otherwise I'll do it eventually.
I need to know exactly why a token failed verification.
Using the
jwt.verify
function I don't know the reason as it might be expired or wrongly signed.So I have implemented the following workaround:
I would like to suggest throwing such errors from
jwt.verify
and only returningtrue
in case of success (never returnfalse
).I could prepare PR but it's a breaking change, so I'm not sure if you accept it.
Maybe as a separate
verify_unsafe
function or add a booleanthow=false
flag to the existing func?What do you think?