mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
Merge 63912b6075
into edc299a043
This commit is contained in:
commit
bb62133aac
@ -135,6 +135,9 @@ export function useCookie<T = string | null | undefined> (name: string, _opts?:
|
||||
}
|
||||
} else if (import.meta.server) {
|
||||
const nuxtApp = useNuxtApp()
|
||||
if (!isEqual(cookie.value, cookies[name])) {
|
||||
writeServerTempararyCookie(useRequestEvent(nuxtApp), name, cookie.value)
|
||||
}
|
||||
const writeFinalCookieValue = () => {
|
||||
if (opts.readonly || isEqual(cookie.value, cookies[name])) { return }
|
||||
nuxtApp._cookies ||= {}
|
||||
@ -186,6 +189,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 = {}) {
|
||||
if (event) {
|
||||
// update if value is set
|
||||
|
Loading…
Reference in New Issue
Block a user