Add support for express v5
Add support for Express v5.0
After upgrading to express v5.0.0 the compilation fails with the following error:
app.use(
/\/((?!healthcheck).)*/, // Token verification activated except for healthcheck request
expressjwt({
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: jwksUri
}) as GetVerificationKey,
algorithms: ['RS256']
})
);
error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type '{ (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: NextFunction): Promise<...>; unless: (options: Params) => { ...; }; }' is not assignable to parameter of type 'Application<Record<string, any>>'.
Type '{ (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: NextFunction): Promise<...>; unless: (options: Params) => { ...; }; }' is missing the following properties from type 'Application<Record<string, any>>': init, defaultConfiguration, engine, set, and 63 more.
possible Workaround:
app.use(
/\/((?!healthcheck).)*/, // Token verification activated except for healthcheck request
async (req: any, res: any, next: NextFunction) => expressjwt({
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: jwksUri
}) as GetVerificationKey,
algorithms: ['RS256']
})(req, res, next) as Promise<void>
);
Background: middlewares are considered async now and Request, Response interfaces are a little bit different.
Thank you for the quick response, but unfortunately the workaround does not solve the issue, the compilation still fails:
error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type '(req: any, res: any, next: NextFunction) => Promise<void | NodeJS.Immediate>' is not assignable to parameter of type 'Application<Record<string, any>>'.
Type '(req: any, res: any, next: NextFunction) => Promise<void | Immediate>' is missing the following properties from type 'Application<Record<string, any>>': init, defaultConfiguration, engine, set, and 63 more.
@quinarygio do you have the as Promise<void> in your code?
@quinarygio do you have the
as Promise<void>in your code?
Sorry I was missing it, as I copied from the received email. It works now ! Thank you
Seems like the main-problem is, that it is wrapping calling next with setImmediate so the return type is not matching.
I can confirm the new version works well now with express v5, thank you! 😃
Tested on
- express: 5.0.1
- express-jwt: 8.5.1