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

Middleware NextRequest params type error #4817

Closed
terrierscript opened this issue Jul 2, 2022 · 5 comments · Fixed by #4926
Closed

Middleware NextRequest params type error #4817

terrierscript opened this issue Jul 2, 2022 · 5 comments · Fixed by #4926
Labels
bug Something isn't working documentation Relates to documentation middleware Related to middleware TypeScript Issues relating to TypeScript upstream The issue dervies from one of next-auth dependencies

Comments

@terrierscript
Copy link
Contributor

terrierscript commented Jul 2, 2022

What is the improvement or update you wish to see?

https://next-auth.js.org/configuration/nextjs#wrap-middleware

In this documentation, wrap middleware get req: NextRequest & { nextauth: { token: JWT | null } } but this code got typescript error.

error TS2345: Argument of type '[(req: NextRequest & { nextauth: { token: JWT; }; }) => void]' is not assignable to parameter of type 'WithAuthArgs'.
  Type '[(req: NextRequest & { nextauth: { token: JWT; }; }) => void]' is not assignable to type '[NextRequest]'.
    Type '(req: NextRequest & { nextauth: { token: JWT; }; }) => void' is not assignable to type 'NextRequest'.

Is there any context that might help us understand?

I think this issue has some options.

  • Improve code types: maybe like NextMiddlewareWithJWT
  • Improve doc: append @ts-ignore ( for workaround )

Does the docs page already exist? Please link to it.

https://next-auth.js.org/configuration/nextjs#wrap-middleware

@terrierscript terrierscript added documentation Relates to documentation triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Jul 2, 2022
@riccardogiorato
Copy link

I'm having the same issue with a simple project with:

  • next 12.2.0
  • next-auth 4.8.0

@flux0uz
Copy link

flux0uz commented Jul 5, 2022

Same here:

  • next: 12.1.6
  • next-auth: 4.7.0

@Dannyisadog
Copy link

Same here:

  • next: 12.2.1-canary.2
  • next-auth: 4.6.1

@Rhym
Copy link

Rhym commented Jul 13, 2022

Same here:

  • next: 12.2.2
  • next-auth: 4.10.0

@balazsorban44 balazsorban44 added bug Something isn't working TypeScript Issues relating to TypeScript middleware Related to middleware upstream The issue dervies from one of next-auth dependencies and removed triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Jul 13, 2022
@balazsorban44
Copy link
Member

This is partially an upstream issue in Next.js, here is a PR for it vercel/next.js#38625

I also opened #4926 which will fix this issue, without needing any workarounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Relates to documentation middleware Related to middleware TypeScript Issues relating to TypeScript upstream The issue dervies from one of next-auth dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants