NuxtN
Nuxt2y ago
1 reply
schmidi

navigateTo inside plugin not working

Hi!

I need some help with using navigateTo inside a plugin.
In my fetch-method i have onResponseError which looks for a 401 status.
Works fine, however my navigateTo won't redirect me to the login page.

I tried with two different methods, but both won't work.

async onResponseError({ response }) {
  if (response.status === 401) {
    console.log("401") // gets printed
    
    await callWithNuxt(nuxtApp, navigateTo, [
      "/user/login",
      { replace: true, redirectCode: 401 },
    ])
  }
}


onResponseError({ response }) {
  if (response.status === 401) {
    console.log("401") // gets printed
    
    return navigateTo("/user/login")
  }
}


Maybe someone can help me figuring out why it won't reconnect me.
Thanks!
Was this page helpful?