From 1586323ea0bc0ec3d06e67d7294778e86707541e Mon Sep 17 00:00:00 2001 From: Hampus Hallkvist Date: Thu, 7 Nov 2024 20:18:26 +0100 Subject: [PATCH] fix: Attempt at fixing feature flag --- src/components/shared/feature.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/components/shared/feature.ts b/src/components/shared/feature.ts index 27626c1..450d5bf 100644 --- a/src/components/shared/feature.ts +++ b/src/components/shared/feature.ts @@ -1,9 +1,28 @@ import featureFlags from "@/feature_flags" import Cookies from "js-cookie" +import { cookies } from "next/headers" export function feature(feature: keyof typeof featureFlags) { + // Server side + if (window === null) { + const cookie = cookies() + + const result = cookie.get("vercel-flag-overrides") + if (result != null) { + return parseCookie(feature, result.value) + } + return null + } + + // Client side const rawOverrides = Cookies.get("vercel-flag-overrides") + return parseCookie(feature, rawOverrides) +} +function parseCookie( + feature: keyof typeof featureFlags, + rawOverrides: string | undefined +) { const overrides = rawOverrides == null ? {}