Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for express v5 #348

Open
quinarygio opened this issue Nov 4, 2024 · 6 comments
Open

Add support for express v5 #348

quinarygio opened this issue Nov 4, 2024 · 6 comments

Comments

@quinarygio
Copy link

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.
@KillerCodeMonkey
Copy link

KillerCodeMonkey commented Nov 7, 2024

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.

@quinarygio
Copy link
Author

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.

@KillerCodeMonkey
Copy link

@quinarygio do you have the as Promise<void> in your code?

@quinarygio
Copy link
Author

@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

@KillerCodeMonkey
Copy link

Seems like the main-problem is, that it is wrapping calling next with setImmediate so the return type is not matching.

@hongbo-miao
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants