Also handle case where there are no cookies yet
This commit is contained in:
parent
c256e9c0cc
commit
55775d9d37
|
@ -23,5 +23,11 @@ export const setCookie = (name: string, val: string, opts?: CookieOptions) => {
|
||||||
|
|
||||||
// Note that this intentionally ignores the case where multiple cookies have
|
// Note that this intentionally ignores the case where multiple cookies have
|
||||||
// the same name but different paths. Hopefully we never need to think about it.
|
// the same name but different paths. Hopefully we never need to think about it.
|
||||||
export const getCookies = (cookies: string) =>
|
export const getCookies = (cookies: string) => {
|
||||||
Object.fromEntries(cookies.split(';').map(decodeCookie))
|
const data = cookies.trim()
|
||||||
|
if (!data) {
|
||||||
|
return {}
|
||||||
|
} else {
|
||||||
|
return Object.fromEntries(data.split(';').map(decodeCookie))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user