Denoder / nuxt-module-alternatives

Alternative modules to use while waiting for Nuxt 3 Compatibility
MIT License
144 stars 14 forks source link

Redirects cause 'parentNode' of null error #96

Closed toniengelhardt closed 2 years ago

toniengelhardt commented 2 years ago

Scenario: I'm logged out and have some redirects defined like

auth: {
  globalMiddleware: true,
  redirect: {
    login: '/login',
    logout: '/login',
    callback: '/login',
    home: '/write',
  }
}

The login page has

definePageMeta({
  layout: 'auth',
  auth: 'guest',
})

while the /write page uses the default layout.

When I try to load a page that is protected by auth, e.g. /write I'm correctly redirected, but get this error

Screen Shot 2022-10-17 at 17 28 52

and the styles are messed up.

I can also see that the code in default layout onMounted is executed before the redirect, which should not be the case, aka. the /write page should not be mounted at all right?

zaeval commented 2 years ago

Could you tell me about the version of nuxt that you are using and the environment?

zaeval commented 2 years ago

And in my case, global Middleware has a lot of problems, so I don't use it, but I usually use it by inserting the source code from a file in pages/*. Eventually, it also runs isLoggedIn on the server side, so it works the same way as middleware.

if($auth.isLoggedIn)
    router.push({name:''});
toniengelhardt commented 2 years ago

@zaeval thanks for taking a look!

I'm using the latest nuxt-edge version, currently nuxt@3.0.0-rc.13-27768654.09e5534 with ssr: false.

modules: [
    // ...
    '@nuxtjs-alt/auth',
    '@nuxtjs-alt/http', // Needed for alt auth.
    // ...
]

I also have this global middleware:

export default defineNuxtRouteMiddleware((to, from) => {
  if (to.path === '/') {
    return navigateTo('/write', { redirectCode: 301 })
  }
})

Not sure if that interferes somehow?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.