You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe this is how it should work, but I spent a lot of time trying to figure out why the cache doesn't work.
I used a test with namespaces from your library. And when using asynchronous key this test fails.
If key is async then
verifier(token) => Promise<result>
const user = formatUser ? formatUser(result) : result // Promise<result>
request[decoratorName] = user // Promise<result>
And key should be async because it shouldn't be called under TTL.
For example, I use AWS KMS, and the library should not do kms.fetchPublicKey() for every incoming request. I can of course use my own cache for public keys, but this is supported out of the box in fast-jwt.
The text was updated successfully, but these errors were encountered:
Prerequisites
Fastify version
4.26.1
Plugin version
8.0.0
Node.js version
20
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
m1
Description
An example from the documentation looks like this:
Steps to Reproduce
But this example creates a new verifier instance and a new cache instance for each request:
request.jwtVerify(next=undefined)
function requestVerify (options, next=undefined)
options = {}
if (next === undefined) {
request[jwtVerifyName](options, function (err, val) {
function requestVerify (options={...}, next=function)
function verify (secretOrPublicKey, callback)
if (useLocalVerifier) {
and useLocalVerifier is trueconst localVerifier = createVerifier(verifierOptions)
cache: createCache(cacheSize),
src/verifier.js#L518So, this config should call
key: fn
once, but withrequest.jwtVerify()
it'sno-cache
policy.Expected Behavior
So, correct usage is:
Maybe this is how it should work, but I spent a lot of time trying to figure out why the cache doesn't work.
I used a test with namespaces from your library. And when using asynchronous
key
this test fails.If
key
isasync
thenverifier(token) => Promise<result>
const user = formatUser ? formatUser(result) : result // Promise<result>
request[decoratorName] = user // Promise<result>
And
key
should beasync
because it shouldn't be called under TTL.For example, I use
AWS KMS
, and the library should not dokms.fetchPublicKey()
for every incoming request. I can of course use my own cache for public keys, but this is supported out of the box in fast-jwt.The text was updated successfully, but these errors were encountered: