Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix theme cookie parsing
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent c2a55bb commit 4bf1609
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions functions/_middleware.ts
Expand Up @@ -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();
}
Expand Down

0 comments on commit 4bf1609

Please sign in to comment.