Closed yidongw closed 1 year ago
Hi @yidongw - thanks for raising this.
Looks like you're creating a new instance of the jwt middleware (and expressJwtSecret
) for every request:
export const jwtCheck = (req: Request, res: Response, next: NextFunction) => {
return jwt({
secret: jwksRsa.expressJwtSecret({
...
}),
...
})(req, res, next)
}
You should only create one:
export const jwtCheck = jwt({
secret: jwksRsa.expressJwtSecret({
...
}),
...
})
oh that's why! thank you so much!
No problem 👍
Describe the problem
I used the following code to fetch the secret from auth0
The secret returned from auth0 doesn't change that often, so I was hoping that
expressJwtSecret
would cache the response for me. I even tried to extend the cache time by addingcacheMaxAge: 3600000
However, when I check the performance in sentry, I noticed that for every call comes in,
expressJwtSecret
still needs to make a call to auth0. This will take 100ms to 700ms to finish and it is now becoming our performance bottleneck.What was the expected behavior?
For the same JWT,
expressJwtSecret
should only make a call once everycacheMaxAge
.expressJwtSecret
would store the response in the cacheReproduction
Environment