Based on the information provided in the extracts, it seems like you're trying to redirect unauthenticated users to the /login page using Next.js middleware. However, you're experiencing issues with the content not rendering correctly.
One possible issue could be related to the execution order of middleware and other configurations in Next.js. According to the Next.js documentation (https://nextjs.org/docs/app/building-your-application/routing/middleware), the execution order is as follows:
headers from next.config.js
redirects from next.config.js
- Middleware (
rewrites, redirects, etc.)
beforeFiles (rewrites) from next.config.js
- Filesystem routes (
public/, _next/static/, pages/, app/, etc.)
afterFiles (rewrites) from next.config.js
- Dynamic Routes (
/blog/[slug])
fallback (rewrites) from next.config.js
If you have other configurations in your next.config.js file that might interfere with your middleware, you might want to check them.
Another potential issue could be related to how you're defining the paths that your middleware will run on. The matcher configuration in your middleware is excluding certain paths like api, _next/static, _next/image, favicon.ico, and images. If your login page or any of its resources fall under these paths, they might not be processed correctly by your middleware.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: