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

Nuxt Bridge Middleware Chain Not Breaking on navigateTo(), abortNavigation() #1101

Open
atomiomi opened this issue Feb 7, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@atomiomi
Copy link

atomiomi commented Feb 7, 2024

Environment

  • Operating System: Darwin
  • Node Version: v18.17.1
  • Nuxt Version: 2.17.2
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: [email protected]
  • Builder: webpack
  • User Config: bridge, router, serverHandlers, devServerHandlers, devServer, typescript, nitro, buildModules
  • Runtime Modules: -
  • Build Modules: (), @nuxt/[email protected]

Reproduction

Reproduction repo: https://github.com/atomiomi/nuxt-bridge-middlewares
The repo has README with steps to reproduce

Describe the bug

In Nuxt Bridge, when a middleware uses the navigateTo(), abortNavigation() utility to redirect the user, the middleware chain does not break as expected. This behavior results in subsequent middlewares being called, potentially leading to errors. This issue is particularly problematic in scenarios where a root middleware checks for user authentication and attempts to block access to a page.

Additional context

No response

Logs

No response

@wattanx wattanx added bug Something isn't working and removed pending triage labels Feb 8, 2024
@wattanx wattanx removed the bug Something isn't working label Feb 9, 2024
@wattanx
Copy link
Collaborator

wattanx commented Feb 9, 2024

Looking at the comments on this issue, etc., this behavior appears to be as expected.
nuxt/nuxt#20696

@atomiomi
Copy link
Author

atomiomi commented Feb 9, 2024

Hey @wattanx thank you for the quick response.
I think the issue that you've linked describes another bug, which is order in which middlewares are called.

The issue I'm describing is that child middleware shouldn't be called at all.
I setup redirects just for demonstration purposes in my repo.

I've prepared another repo to show the issue
https://stackblitz.com/edit/github-emkswl?file=pages%2Findex.vue

There are 2 pages:

  • home: doesn't have any middlewares
  • dashboard: has authorize middleware, and then load-data middleware

authorized middleware always redirects user to home page because user is not authorized.
and expected behavior is that load-data middleware woudn't be called since aurthorize return navigateTo.
But load-data called anyway

If you go to /dashboard page you will see in console

>>> Authorization middleware called
>>> Load data middleware called

@wattanx
Copy link
Collaborator

wattanx commented Feb 10, 2024

I finally understood.
I misunderstood the issue 🙈

@wattanx wattanx added the bug Something isn't working label Feb 10, 2024
@guska8
Copy link

guska8 commented Oct 28, 2024

i have the same problem in nuxt bridge 3.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants