Skip to content
BuildBase

Feature flags overview

Gate features by subscription plan or target specific users for beta rollouts.

BuildBase provides two types of feature flags. Workspace features are tied to plans - upgrade to Pro and get analytics. User features target specific users - assign users directly, target them by user tag or through user lists (and, over the API, audience lists), or allow a flag for all users.

import {
  WhenUserFeatureEnabled,
  WhenWorkspaceFeatureDisabled,
  WhenWorkspaceFeatureEnabled,
} from '@buildbase/sdk/react';

function Dashboard() {
  return (
    <>
      <WhenWorkspaceFeatureEnabled slug="advanced-analytics">
        <AdvancedAnalytics />
      </WhenWorkspaceFeatureEnabled>

      <WhenWorkspaceFeatureDisabled slug="advanced-analytics">
        <p>Upgrade to Pro for analytics.</p>
      </WhenWorkspaceFeatureDisabled>

      <WhenUserFeatureEnabled slug="beta-editor">
        <NewEditor />
      </WhenUserFeatureEnabled>
    </>
  );
}

To gate a capability you sell, by its slug and with the plan's answer, use Entitlement Checks: useEntitlement and WhenEntitled follow plan changes and add-ons, and tell a locked feature from one the plan does not mention.

Note

useEntitlement and WhenEntitled: Requires @buildbase/sdk 1.0.0 or later. On 0.0.90 and earlier, gate on the plan with WhenWorkspaceFeatureEnabled or WhenSubscriptionToPlans.

Before you start

Create feature flags in the BuildBase console: Users in the left rail, then Features under Users for a user flag or under Workspaces for a workspace flag. A new flag is switched off, and a flag that is off turns on for nobody, so switch it on: Enable on a user flag, Enabled on a workspace flag. Workspace features are configured per plan, or set to allow all to turn one on for every workspace. User features are targeted to individual users, user tags or user lists in the console (Add users, Add user tags, Add user lists), to audience lists over the API only, or allowed for all users. Step by step, with screenshots: user flags and workspace flags.

Components

ComponentRenders when
WhenWorkspaceFeatureEnabledWorkspace feature is on (tied to plan, or allowed for all workspaces)
WhenWorkspaceFeatureDisabledWorkspace feature is off
WhenUserFeatureEnabledUser feature targets the current user (directly, by tag, via a user or audience list, or allowed for all users)
WhenUserFeatureDisabledUser feature does not target the current user

All take a slug prop (the feature identifier from the dashboard) and children.

WhenWorkspaceFeatureEnabled also takes whileUnknown, for a slug the workspace has no value for yet, such as a flag you created after the workspace loaded. 'allow' shows the children. The default, 'deny', hides them. Requires @buildbase/sdk 1.0.0 or later.

<WhenWorkspaceFeatureEnabled slug="new-dashboard" whileUnknown="allow">
  <NewDashboard />
</WhenWorkspaceFeatureEnabled>

useUserFeatures()

For a user flag outside JSX, or several at once, read the hook instead of a component. It must be used inside SaaSOSProvider.

import { useUserFeatures } from '@buildbase/sdk/react';

function EditorEntry() {
  const { isFeatureEnabled, loading } = useUserFeatures();
  if (loading) return null;
  return isFeatureEnabled('beta-editor') ? <BetaEditor /> : <Editor />;
}
Property / MethodDescription
featuresEvery user flag for the signed-in user, as { [featureId]: boolean }
isFeatureEnabled(featureId)Whether the flag is on for this user
loadingtrue while the flags are being fetched
errorThe last fetch's error, or null
refetch()Fetch the flags again, so a change made in the console shows without a page reload

isLoading and refreshFeatures() are the old names of loading and refetch(), kept for older code.

Combining with other components

Feature flags compose naturally with permissions, subscriptions, and credits:

import {
  Permission,
  WhenCreditsAvailable,
  WhenPermission,
  WhenWorkspaceFeatureEnabled,
} from '@buildbase/sdk/react';

function AISection() {
  return (
    <WhenWorkspaceFeatureEnabled slug="ai-generation">
      <WhenPermission permission={Permission.WORKSPACE_BILLING_MANAGE}>
        <WhenCreditsAvailable min={10}>
          <GenerateButton />
        </WhenCreditsAvailable>
      </WhenPermission>
    </WhenWorkspaceFeatureEnabled>
  );
}

Pre-built features screen

openWorkspaceSettings('features') shows a built-in screen where workspace admins can toggle user-managed feature flags.

Changing who gets a user flag from your backend

You choose who gets a user flag in the console, and you can make the same changes from your own code with an org API token. A sign-up flow or a support tool can then put someone in a beta without anyone opening the console.

curl -X PATCH https://api.console.buildbase.app/api/features/$FEATURE_ID/users/add \
  -H "Authorization: $BUILDBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"users":["USER_ID"]}'
TargetAddBody
UsersPATCH /api/features/:id/users/add{ "users": [...] }
User listsPATCH /api/features/:id/user-lists/add{ "userLists": [...] }
Audience listsPATCH /api/features/:id/audience-lists/add{ "audienceLists": [...] }
User tagsPATCH /api/features/:id/tags/add{ "tags": [...] }
Audience tagsPATCH /api/features/:id/audience-tags/add{ "tags": [...] }

Each has a matching /remove. Adding a target needs a plan that includes advanced flag targeting. Removing one never does, so a plan without it can always hand a flag back to everybody.

Limitations and behavior

BehaviorDetail
Toggle sourceUser-managed workspace features toggle via updateFeature(workspaceId, key, value) on useSaaSWorkspaces() or bb.features.update(workspaceId, key, value) server-side. Plan-tied workspace features follow the plan, and user feature targeting is set in the console or over the org API (above). A request that only names features the workspace cannot change is refused with 403 FEATURE_NOT_USER_MANAGED, listing them in features; beside ones it can change, they are skipped and named in the answer's ignoredFeatures
PropagationChanges take effect on the next page load or session refresh (not instant for active sessions)
CachingFlags are fetched with the session data and cached locally. No additional API calls per render
RollbackDisabling a flag hides gated UI immediately on next load. Running code is not interrupted
AnalyticsNo built-in A/B analytics - you must track conversions yourself (e.g. via workflows or your own analytics)
NestingFeature flag components can be nested with permission and subscription gates - they compose naturally

Next Steps