From 759534a8b8189c25d665b34db1cdf7f0b7a8f31e Mon Sep 17 00:00:00 2001 From: Adam Howard <91115+codeincontext@users.noreply.github.com> Date: Thu, 31 Oct 2024 18:26:50 +0100 Subject: [PATCH] feat: use featureFlagGroup claim for feature flags --- apps/nextjs/src/lib/feature-flags/bootstrap.ts | 12 +++++++++--- apps/nextjs/src/middlewares/auth.middleware.ts | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/nextjs/src/lib/feature-flags/bootstrap.ts b/apps/nextjs/src/lib/feature-flags/bootstrap.ts index 0f49aa8a5..caa566a99 100644 --- a/apps/nextjs/src/lib/feature-flags/bootstrap.ts +++ b/apps/nextjs/src/lib/feature-flags/bootstrap.ts @@ -32,15 +32,21 @@ function getDistinctIdFromCookie(headers: ReadonlyHeaders) { } export async function getBootstrappedFeatures(headers: ReadonlyHeaders) { - const { userId } = auth(); + const { userId, sessionClaims } = auth(); const distinctId = userId ?? getDistinctIdFromCookie(headers) ?? "0"; log.info("Evaluating feature flags for", distinctId); + + const personProperties = sessionClaims?.labs?.featureFlagGroup + ? { featureFlagGroup: sessionClaims.labs.featureFlagGroup } + : undefined; + const features = await posthogAiBetaServerClient.getAllFlags(distinctId, { - // Only bootstrap flags which don't depend on user properties - // These are typically flags representing new features + // Only bootstrap flags which don't depend on PII onlyEvaluateLocally: true, + personProperties, }); + log.info("Bootstrapping feature flags", features); return features; } diff --git a/apps/nextjs/src/middlewares/auth.middleware.ts b/apps/nextjs/src/middlewares/auth.middleware.ts index f67bbb0ba..d282fd323 100644 --- a/apps/nextjs/src/middlewares/auth.middleware.ts +++ b/apps/nextjs/src/middlewares/auth.middleware.ts @@ -13,6 +13,7 @@ declare global { labs: { isDemoUser: boolean | null; isOnboarded: boolean | null; + featureFlagGroup: string | null; }; } }