Accessing $nuxt inside a plugin?

Viewed 168

Is it possible to access the $nuxt object inside a plugin? My use case is that I want to run the "this.$nuxt.refresh()" method inside a plugin. Tried

export default async function ({
  $axios,
  redirect,
  app,
  $nuxt
}) {
  await $axios.onError(error => {
    if (error.response.status === 401 && error.response.data.detail != null && error.response.data.detail.includes("Invalid token")) {
      app.$auth.strategy.token.reset()
      $nuxt.refresh() // This does not work, refresh is undefined
    }
  })
}

I also tried just importing Nuxt or accessing it from app.$nuxt.refresh() but still, none of these solutions seem to work. Is there an way to run refresh here or am I forced to use location.reload()?

E.g this does not work

export default function ({ $auth, router, app }) {
    app.$nuxt.refresh() // Does not work
    app.nuxt.refresh() // Does not work
  }
  return
}
1 Answers
Related