You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a new NextResponse is returned from middleware, the response seems to be ignored. Instead of rendering what is returned from middleware, the route itself is rendered.
Here is a repo demonstrating the issue: https://github.com/bharatari/middleware-error. I generated the app with create-next-app, added the edge runtime config to the page and added a middleware file.
If you run this app with wrangler, you'll see that the route is rendered instead of the response returned from the middleware.
With next dev, you'll see the middleware response rendered (as expected).
Pages Deployment Method
None
Pages Deployment ID
No response
Additional Information
Additional context in case it is helpful (although not necessary to debug the issue):
I noticed this while using the Next.js middleware from clerk/nextjs (an authentication provider). The middleware returns an interstitial page to refresh an expired JWT token, but with next-on-pages, this interstitial page isn't rendered even when it's returned from middleware. The app goes on to render the route even though authentication hasn't actually completed yet.
Would you like to help?
Would you like to help fixing this bug?
The text was updated successfully, but these errors were encountered:
Thank you very much for providing a reproduction and opening this bug report.
It looks like we didn't quite implement a certain scenario properly with how we handled middleware 🙁
I've just opened a PR that should address it (#284), and I would welcome you to try out the prerelease listed in that PR and check that it fixes your problem.
This issue currently prevents Clerk from functioning at all on Cloudflare with errors like:
Error: Clerk: auth() was called but it looks like you aren't using `authMiddleware` in your middleware file. Please use `authMiddleware` and make sure your middleware matcher is configured correctly and it matches this route or page. See https://clerk.com/docs/quickstarts/get-started-with-nextjs
next-on-pages environment related information
System:
Platform: linux
Arch: x64
Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023
CPU: (12) x64 12th Gen Intel(R) Core(TM) i7-1255U
Memory: 8 GB
Shell: /bin/bash
Binaries:
Node: 18.15.0
Yarn: 1.22.19
npm: 9.5.0
pnpm: 8.3.1
Package Manager Used: npm
Relevant Packages:
@cloudflare/next-on-pages: 1.0.1
vercel: N/A
next: 13.4.4
Description
When a
new NextResponse
is returned from middleware, the response seems to be ignored. Instead of rendering what is returned from middleware, the route itself is rendered.next dev
(expected behavior):wrangler
(incorrect):As of Next 13.1, this form of returning a new NextResponse from middleware should be valid:
https://nextjs.org/docs/app/building-your-application/routing/middleware#producing-a-response
Reproduction
Here is a repo demonstrating the issue: https://github.com/bharatari/middleware-error. I generated the app with create-next-app, added the edge runtime config to the page and added a middleware file.
If you run this app with
wrangler
, you'll see that the route is rendered instead of the response returned from the middleware.With
next dev
, you'll see the middleware response rendered (as expected).Pages Deployment Method
None
Pages Deployment ID
No response
Additional Information
Additional context in case it is helpful (although not necessary to debug the issue):
I noticed this while using the Next.js middleware from
clerk/nextjs
(an authentication provider). The middleware returns an interstitial page to refresh an expired JWT token, but with next-on-pages, this interstitial page isn't rendered even when it's returned from middleware. The app goes on to render the route even though authentication hasn't actually completed yet.Would you like to help?
The text was updated successfully, but these errors were encountered: