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 query params functionality is broken #32480

Closed
ardaerzin opened this issue Dec 14, 2021 · 8 comments
Closed

Middleware query params functionality is broken #32480

ardaerzin opened this issue Dec 14, 2021 · 8 comments
Labels
Middleware Related to Next.js Middleware

Comments

@ardaerzin
Copy link

What version of Next.js are you using?

12.0.7

What version of Node.js are you using?

16.13.1

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

We've been keeping an eye on the middleware functionality since the launch of v12. one use case we are interested in, is to authenticate users via magic links. While we can achieve this functionality, when we want to remove the token from url, we are getting errors due to infinite redirections. token is not being removed and the same thing is called over and over again until the function crashes.

others and us also saw this on examples provided by Vercel

Expected Behavior

we expect the functionality to work as described here

To Reproduce

visit this url

@ardaerzin ardaerzin added the bug Issue was opened via the bug report template. label Dec 14, 2021
@Javimtib92
Copy link

I'm experiencing the same issue with the exact same behaviour.
Our case is that we are adding event listeners in _app file that check for auth state with a 3rd party server based on some query params we get from a magic link. This issue is causing the _app to render twice and therefore attaching the event listeners two times, then those internally are supposed to perform a redirection but they enter in a loop of redirections that crashes the app.

@ardaerzin
Copy link
Author

is this being tracked? I mean, the official example is broken for over a month now. any information from the team will be helpful for us to plan our next tasks

@balazsorban44 balazsorban44 added kind: bug Middleware Related to Next.js Middleware and removed bug Issue was opened via the bug report template. labels Dec 20, 2021
@bryanrsmith
Copy link
Contributor

Same here, with a slightly different use case--I'm using middleware to redirect some requests to an external site, and the query params that the middleware receives are being attached to the external redirect target. Seems potentially pretty dangerous 😬

@javivelasco
Copy link
Member

This is now supported! You can remove query string parameters filtering them out with the URLSearchParams API.

@bryanrsmith
Copy link
Contributor

@javivelasco I believe this case was specifically for redirects, not rewrites. I have verified that the issue has not been resolved. I can repro only when deployed to Vercel, and not when running locally. It maybe a vercel bug and not a next.js bug. Here's a repro:

https://next-middleware-redirects.vercel.app/

Code: https://github.com/bryanrsmith/next-middleware-redirects

@bryanrsmith
Copy link
Contributor

bryanrsmith commented Feb 15, 2022

@javivelasco There is still a problem here--see repro above. Would you like me to create a separate issue?

@balazsorban44
Copy link
Member

Yes, please open a separate issue, we appreciate it! 🙏

@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 Mar 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Middleware Related to Next.js Middleware
Projects
None yet
Development

No branches or pull requests

5 participants