Open psycongaroo opened 2 years ago
Do you mind creating a reproduction on GitHub or CodeSandBox?
Hi @shinguweb96. You probably need to import useCookie
from h3
not #app
for server/api
and server/middleware
.
Please see example in docs: https://v3.nuxtjs.org/docs/usage/cookies#handling-cookies-in-api-routes
@Atinux Hi, here: https://stackblitz.com/edit/nuxt-starter-yx9zm5 (yarn dev)
@pi0 Hi, sorry is not for API Middleware, I was talking about Nuxt-Bridge and route middleware (nuxt 2).
I think this is due to the fact that getCurrentInstance()
used by useNuxtApp()
(used by useCookie()
): https://github.com/nuxt/framework/blob/main/packages/nuxt3/src/app/nuxt.ts#L196
Since in Nuxt 2, the router middleware are handled with router.beforeEach
, the Vue app has not been instanciated yet.
We are working on the router middleware for Nuxt 3 on https://github.com/nuxt/framework/discussions/2468, potentially this would help solve the issue.
Thank you @Atinux, there is any eta about #2468?
Cc @danielroe
@Atinux @danielroe @pi0 same identical problem using $fetch inside middleware
I know is same reason about useCookie, but I wanted to report it too.
@Atinux @danielroe @pi0 same identical problem using $fetch inside middleware
I know is same reason about useCookie, but I wanted to report it too.
Same issue here, using $fetch inside a middleware
Environment
Linux
v16.13.1
2.16.0-27358576.777a4b7f
yarn@1.22.17
Webpack
target
,head
,publicRuntimeConfig
,privateRuntimeConfig
,loading
,css
,buildModules
,build
,router
,components
,vite
,bridge
,plugins
-
@vueuse/core/nuxt@6.9.2
,@nuxt/bridge-edge@3.0.0-27369360.33ebb01
,@pinia/nuxt@0.1.8
Reproduction
Describe the bug
useCookie not working in middleware:
Additional context
No response
Logs
No response