Skip to content

Commit

Permalink
feat: use featureFlagGroup claim for feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
codeincontext committed Oct 31, 2024
1 parent b2eba2a commit 759534a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions apps/nextjs/src/lib/feature-flags/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions apps/nextjs/src/middlewares/auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare global {
labs: {
isDemoUser: boolean | null;
isOnboarded: boolean | null;
featureFlagGroup: string | null;
};
}
}
Expand Down

0 comments on commit 759534a

Please sign in to comment.