mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-01 18:07:22 +00:00
fix(nuxt): add cookies on server side fetching useCookie
This commit is contained in:
parent
5d7d4d75af
commit
fd5220c6f7
@ -63,6 +63,9 @@ export function useCookie<T = string | null | undefined> (name: string, _opts?:
|
|||||||
}
|
}
|
||||||
} else if (process.server) {
|
} else if (process.server) {
|
||||||
const nuxtApp = useNuxtApp()
|
const nuxtApp = useNuxtApp()
|
||||||
|
if (!isEqual(cookie.value, cookies[name])) {
|
||||||
|
writeServerTempararyCookie(useRequestEvent(nuxtApp), name, cookie.value)
|
||||||
|
}
|
||||||
const writeFinalCookieValue = () => {
|
const writeFinalCookieValue = () => {
|
||||||
if (!isEqual(cookie.value, cookies[name])) {
|
if (!isEqual(cookie.value, cookies[name])) {
|
||||||
writeServerCookie(useRequestEvent(nuxtApp), name, cookie.value, opts)
|
writeServerCookie(useRequestEvent(nuxtApp), name, cookie.value, opts)
|
||||||
@ -99,6 +102,16 @@ function writeClientCookie (name: string, value: any, opts: CookieSerializeOptio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function writeServerTempararyCookie (event: H3Event, name: string, value: any) {
|
||||||
|
// add cookie to req.headers.cookie ex) cookie is added or updated in plugin
|
||||||
|
if (event) {
|
||||||
|
const cookie = event.node.req.headers.cookie || ''
|
||||||
|
event.node.req.headers.cookie = cookie
|
||||||
|
? `${cookie}; ${name}=${value}`
|
||||||
|
: `${name}=${value}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function writeServerCookie (event: H3Event, name: string, value: any, opts: CookieSerializeOptions = {}) {
|
function writeServerCookie (event: H3Event, name: string, value: any, opts: CookieSerializeOptions = {}) {
|
||||||
if (event) {
|
if (event) {
|
||||||
// update if value is set
|
// update if value is set
|
||||||
|
Loading…
Reference in New Issue
Block a user