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

redirect action to protected routes(protect with middleware) without authorization will result in URL change #70751

Open
ehsanrezaeee opened this issue Oct 3, 2024 · 2 comments
Labels
bug Issue was opened via the bug report template. Middleware Related to Next.js Middleware. Navigation Related to Next.js linking (e.g., <Link>) and navigation. Performance Anything with regards to Next.js performance.

Comments

@ehsanrezaeee
Copy link

Link to the code that reproduces this issue

https://github.com/ehsanrezaeee/next-redirect-bug

To Reproduce

1.Start the application in development mode
2.Click on the deleteCookies button to make sure you are not authenticated.
3.Click on the redirect to protected route using server action Button
4.URL changes but the page doesn't because of the middleware.

Current vs. Expected behavior

Current Behavior:

  • if you are authenticated using setCookies button (set cookie server action) you can redirect to protectedroute page with either Link or "redirect to protected route using server action" button. However, if you are not authenticated, the Link component will work exaclty as it is but the "redirect to protected route using server action" wont work properly

  • the "redirect to protected route using server action" will redirect to protectedroute and then middleware activate and redirect back to openroute. However, the URL changes to protectedroute

Expected Behavior:

  • if you are not authenticated (no cookie is set), the "URL" should not change when clicking on the "redirect to protected route using server action" button.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Enterprise
  Available memory (MB): 32579
  Available CPU cores: 12
Binaries:
  Node: 22.5.1
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.2.14 // Latest available version is detected (14.2.14).
  eslint-config-next: 14.2.14
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.6.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Middleware, Navigation, Performance

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Other (Deployed)

Additional context

I tested the app with dev, build and production environment. The issue exists in all of them

@ehsanrezaeee ehsanrezaeee added the bug Issue was opened via the bug report template. label Oct 3, 2024
@github-actions github-actions bot added Middleware Related to Next.js Middleware. Navigation Related to Next.js linking (e.g., <Link>) and navigation. Performance Anything with regards to Next.js performance. labels Oct 3, 2024
@abhi12299
Copy link
Contributor

To add more context, this is fixed in the latest canary - I believe a backport should fix this in v14.2

@ehsanrezaeee
Copy link
Author

To add more context, this is fixed in the latest canary - I believe a backport should fix this in v14.2

its a little bit urgent and i dont think canary will be stable soon. but thanks. i have another issue that solved with canary version 14.3 but they didnt release it as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Middleware Related to Next.js Middleware. Navigation Related to Next.js linking (e.g., <Link>) and navigation. Performance Anything with regards to Next.js performance.
Projects
None yet
Development

No branches or pull requests

2 participants