Middleware NextRequest params type error
See original GitHub issueWhat 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:
- Created a year ago
- Reactions:10
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Same here: