This commit is contained in:
kyumoon 2024-11-20 06:35:51 -05:00 committed by GitHub
commit bb62133aac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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