Middleware not working with latest version of Next Js
See original GitHub issue- Review the documentation: https://docs.clerk.dev/
- Search for existing issues: https://github.com/clerkinc/javascript/issues
- Go through package changelog files.
- Provide the Frontend API key from your application dashboard.
Package + Version
-
@clerk/clerk-js
-
@clerk/clerk-react
-
@clerk/nextjs
-
@clerk/remix
-
@clerk/clerk-expo
-
@clerk/backend-core
-
@clerk/clerk-sdk-node
-
@clerk/edge
- other:
Version:
3.6.8
Browser/OS
If applicable e.g. Chrome latest
Description
Currently when running the latest version of Next Js 12.2.0
the following code:
export default withEdgeMiddlewareAuth((req) => {
console.log('Middleware')
})
Throws the error: [Error: A middleware can not alter response's body. Learn more: https://nextjs.org/docs/messages/returning-response-body-in-middleware]
The documentation could also be updated in the clerk docs to support the changes to Next Js middleware in general, which now requires middleware to be at the root of the application.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
next.js - NextJS middleware does not seem to be triggered
Latest versions of NextJS requires user to have a single middleware on the root folder. To be more precise, the middleware file has...
Read more >middleware not working · Discussion #38546 · vercel/next.js
Is there any drawback to making middleware.ts a "reserved" filename? Seems simpler and is similar to the conventions of the new layouts system...
Read more >Advanced Features: Middleware - Next.js
Learn how to use Middleware to run code before a request is completed. ... Install the latest version of Next.js: npm install next@latest....
Read more >How to use middleware in nextjs? - Medium
Nextjs middleware does not run with typescript and throws an error in the terminal. You install typescript, and right now, you do not...
Read more >What's New in Next.js 13 - AppSignal Blog
Version 13 of Next.js, a well-established React framework from the ... When you deal with pages/index.tsx , the running Next.js server will ...
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 FreeTop 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
Top GitHub Comments
Sure thing. We have already started a draft PR but it needs more work as the changes on Next.js side were big.
Yes. We will continue working on Next 12.2 so as to move authentication completely in the
middleware.ts
but our latest release should unblock you.