Hebilicious / authjs-nuxt

AuthJS edge-compatible authentication Nuxt module.
https://authjs-nuxt.pages.dev/
MIT License
246 stars 30 forks source link

nuxt catch-all pages causes infinite redirection with route middlewares #115

Open m0zz094 opened 9 months ago

m0zz094 commented 9 months ago

Environment

Nuxt project info: 14:22:52


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
Hebilicious commented 9 months ago

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?

m0zz094 commented 9 months ago

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