mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
fix(nuxt): don't try to set cookie after redirect (#7288)
This commit is contained in:
parent
f8f5771646
commit
5a69f48244
@ -9,9 +9,9 @@ import { useNuxtApp } from '#app'
|
|||||||
|
|
||||||
type _CookieOptions = Omit<CookieSerializeOptions & CookieParseOptions, 'decode' | 'encode'>
|
type _CookieOptions = Omit<CookieSerializeOptions & CookieParseOptions, 'decode' | 'encode'>
|
||||||
|
|
||||||
export interface CookieOptions<T=any> extends _CookieOptions {
|
export interface CookieOptions<T = any> extends _CookieOptions {
|
||||||
decode?(value: string): T
|
decode?(value: string): T
|
||||||
encode?(value: T): string;
|
encode?(value: T): string
|
||||||
default?: () => T | Ref<T>
|
default?: () => T | Ref<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,8 +38,12 @@ export function useCookie <T = string> (name: string, _opts?: CookieOptions<T>):
|
|||||||
writeServerCookie(useRequestEvent(nuxtApp), name, cookie.value, opts)
|
writeServerCookie(useRequestEvent(nuxtApp), name, cookie.value, opts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nuxtApp.hooks.hookOnce('app:rendered', writeFinalCookieValue)
|
const unhook = nuxtApp.hooks.hookOnce('app:rendered', writeFinalCookieValue)
|
||||||
nuxtApp.hooks.hookOnce('app:redirected', writeFinalCookieValue)
|
nuxtApp.hooks.hookOnce('app:redirected', () => {
|
||||||
|
// don't write cookie subsequently when app:rendered is called
|
||||||
|
unhook()
|
||||||
|
return writeFinalCookieValue()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return cookie as CookieRef<T>
|
return cookie as CookieRef<T>
|
||||||
|
Loading…
Reference in New Issue
Block a user