nuxt-modules / apollo

Nuxt.js module to use Vue-Apollo. The Apollo integration for GraphQL.
https://apollo.nuxtjs.org
MIT License
956 stars 198 forks source link

fix: provide Nuxt app context for useCookie call after async #524

Closed aapokiiso closed 8 months ago

aapokiiso commented 1 year ago

Due to the asynchronous nuxtApp.callHook call in getToken, the Nuxt app context is no longer available when useCookie is called to retrieve the token cookie value. This causes the following error:

[nuxt] A composable that requires access to the Nuxt instance was called
outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function.
This is probably not a Nuxt bug.
Find out more at `https://nuxt.com/docs/guide/concepts/auto-imports#using-vue-and-nuxt-composables`.

With a stack trace (example):

at Module.useRequestEvent (./node_modules/nuxt/dist/app/composables/ssr.js:16:58)
at readRawCookies (./node_modules/nuxt/dist/app/composables/cookie.js:78:62)
at Module.useCookie (./node_modules/nuxt/dist/app/composables/cookie.js:23:19)
at getToken (./node_modules/@nuxtjs/apollo/dist/runtime/composables.mjs:47:68)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ./src/middleware/customer-auth.ts:9:97
at async Object.callAsync (./node_modules/unctx/dist/index.mjs:72:16)
at async ./node_modules/nuxt/dist/pages/runtime/plugins/router.js:130:26

This can be circumvented by explicitly providing the previous Nuxt app context for the useCookie call using the internal callWithNuxt utility.

netlify[bot] commented 1 year ago

Deploy Preview for apollo-module canceled.

Name Link
Latest commit b6116f2469257ea15e164ae71b9b6e556252b251
Latest deploy log https://app.netlify.com/sites/apollo-module/deploys/64a6d5b4ae95c20008e75094
aapokiiso commented 1 year ago

@Diizzayy Hi, is this package still maintained or should we start moving to https://github.com/Diizzayy/nuxt-graphql-client?

hermesalvesbr commented 1 year ago

@Diizzayy Hi, is this package still maintained or should we start moving to https://github.com/Diizzayy/nuxt-graphql-client?

Has the repository really moved?