authjs-nuxt icon indicating copy to clipboard operation
authjs-nuxt copied to clipboard

nuxt catch-all pages causes infinite redirection with route middlewares

Open m0zz094 opened this issue 2 years ago • 2 comments

Environment

Nuxt project info: 14:22:52


  • Operating System: Windows_NT
  • Node Version: v18.17.1
  • Nuxt Version: 3.7.4
  • CLI Version: 3.9.0
  • Nitro Version: 2.6.3
  • Package Manager: [email protected]
  • Builder: -
  • User Config: modules, devtools, alias, devServer
  • Runtime Modules: @hebilicious/[email protected]
  • Build Modules: -

Reproduction

https://github.com/m0zz094/authjs-nuxt-bug

Describe the bug

I have a catch all route where, if the page path is equal to "/reserved-area", i want to add the auth middleware, it looks like this is not working right now

Additional context

No response

Logs

[Vue Router warn]: Detected a possibly infinite redirection in a navigation guard when going from "/reserved-area" to "/login". Aborting to avoid a Stack Overflow.
 Are you always returning a new location within a navigation guard? That would lead to this error. Only return when redirecting or aborting, that should fix this. This might break in production if not fixed.
[nuxt] Calling `useRoute` within middleware may lead to misleading results. Instead, use the (to, from) arguments passed to the middleware to access the new and old routes.
Removing session

m0zz094 avatar Oct 05 '23 12:10 m0zz094

That's an interesting bug that appears to be Nuxt related. As a workaround, could you use a separated page for your reserved-area instead?

Hebilicious avatar Oct 09 '23 03:10 Hebilicious

Hi @Hebilicious, I could try this but ideally I'm creating private pages from a headless CMS so there could be different slugs, I'll open an issue in Nuxt

m0zz094 avatar Oct 09 '23 06:10 m0zz094