From 4bf1609b24d5242849b2bd40e1044694fedf7f15 Mon Sep 17 00:00:00 2001 From: regalijan <r@regalijan.com> Date: Thu, 19 Oct 2023 16:49:56 -0400 Subject: [PATCH] Fix theme cookie parsing --- functions/_middleware.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/functions/_middleware.ts b/functions/_middleware.ts index 02deded..8d9ccfd 100644 --- a/functions/_middleware.ts +++ b/functions/_middleware.ts @@ -116,14 +116,13 @@ async function setTheme(context: RequestContext) { const cookieList = cookies.split("; "); - const value = cookieList.find((c) => { - if (!c.startsWith("chakra-ui-color-mode")) return false; - - return c.split("=")[1]; - }); + const themeCookie = cookieList.find((c) => + c.startsWith("chakra-ui-color-mode") + ); + const theme = themeCookie?.split("=").at(1); - if (!value) context.data.theme = "dark"; - else context.data.theme = value; + if (!theme) context.data.theme = "dark"; + else context.data.theme = theme; return await context.next(); }