Skip to content

Commit

Permalink
fix: Attempt at fixing feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
hampfh committed Nov 7, 2024
1 parent 861ef00 commit 1586323
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/components/shared/feature.ts
Original file line number Diff line number Diff line change
@@ -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
? {}
Expand Down

0 comments on commit 1586323

Please sign in to comment.