Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware does not run when concurrentFeatures is enabled #31803

Closed
saurabhguptarock opened this issue Nov 25, 2021 · 4 comments · Fixed by #37708
Closed

Middleware does not run when concurrentFeatures is enabled #31803

saurabhguptarock opened this issue Nov 25, 2021 · 4 comments · Fixed by #37708
Assignees

Comments

@saurabhguptarock
Copy link

What version of Next.js are you using?

12.0.5-canary.9

What version of Node.js are you using?

14.18.1

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

Middleware does not run and redirects user.

Expected Behavior

Middleware should redirect to login page.

To Reproduce

module.exports = {
  images: {
    deviceSizes: [640],
    domains: ["avatars.dicebear.com"],
    formats: ["image/avif", "image/webp"],
  },
  createRoot: true,
  swcMinify: false,
  experimental: {
    reactRoot: true,
    concurrentFeatures: true,
    serverComponents: true,
  },
};

_middleware.tsx

import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";

export const middleware = (req: NextRequest) => {
  const cookie = req.cookies["auth"];

  if (!cookie) {
    return NextResponse.redirect("/login");
  }
};
@saurabhguptarock saurabhguptarock added the bug Issue was opened via the bug report template. label Nov 25, 2021
@KlotzJesse
Copy link

Just won't work in the main ./pages folder. When added on an api route or /api directly, or in an sub-folder of ./pages it runs.

e.g.
./pages/_middleware.ts wont work
./pages/app/_middleware.ts will work
./pages/api/_middleware.ts will work

Also in 12.0.5-canary.10

@saurabhguptarock
Copy link
Author

Just won't work in the main ./pages folder. When added on an api route or /api directly, or in an sub-folder of ./pages it runs.

e.g. ./pages/_middleware.ts wont work ./pages/app/_middleware.ts will work ./pages/api/_middleware.ts will work

Also in 12.0.5-canary.10

I have my middleware in sub folder but still not running
Screenshot 2021-11-26 at 14 38 45

@huozhi
Copy link
Member

huozhi commented Jun 28, 2022

Resolved with next 12.2

@huozhi huozhi closed this as completed Jun 28, 2022
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants