From 55775d9d37872fc133650d7d26104af87bce79b9 Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Tue, 19 Jul 2022 01:35:34 -0700 Subject: [PATCH] Also handle case where there are no cookies yet --- web/lib/util/cookie.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/web/lib/util/cookie.ts b/web/lib/util/cookie.ts index 4ffee21e..14999fd4 100644 --- a/web/lib/util/cookie.ts +++ b/web/lib/util/cookie.ts @@ -23,5 +23,11 @@ export const setCookie = (name: string, val: string, opts?: CookieOptions) => { // 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. -export const getCookies = (cookies: string) => - Object.fromEntries(cookies.split(';').map(decodeCookie)) +export const getCookies = (cookies: string) => { + const data = cookies.trim() + if (!data) { + return {} + } else { + return Object.fromEntries(data.split(';').map(decodeCookie)) + } +}