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; }; } }