question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Middleware NextRequest params type error

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:10
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
balazsorban44commented, Jul 13, 2022

This is partially an upstream issue in Next.js, here is a PR for it https://github.com/vercel/next.js/pull/38625

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

0reactions
Rhymcommented, Jul 13, 2022

Same here:

  • next: 12.2.2
  • next-auth: 4.10.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Features: Middleware - Next.js
Middleware allows you to run code before a request is completed, then based on the incoming request, you can modify the response by...
Read more >
Type 'NextApiRequest' is missing the following properties from ...
js project. Argument of type 'NextApiRequest' is not assignable to parameter of type 'Request<ParamsDictionary, any, any, ParsedQs, Record< ...
Read more >
Next.js Middleware on Netlify
The MiddlewareRequest object is a more powerful version of the standard NextRequest object. You create it by passing NextRequest to the constructor: import...
Read more >
Request - Slim Framework
Your Slim app's routes and middleware are given a PSR-7 request object that ... You can fetch the appended media type parameters as...
Read more >
High Performance Personalization with Next.js Middleware
Middleware are arbitrary functions that you can write, ... versions of the page for different targeting parameters (e.g. men/women).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found