Skip to content

fix(onboarding): align prompts to selected plan's engine set on Stripe success - #111

Merged
gkhngyk merged 1 commit into
mainfrom
fix/onboarding-align-prompts-to-plan
May 26, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/onboarding-align-prompts-to-plan

Conversation

@gkhngyk

@gkhngyk gkhngyk commented May 26, 2026

Copy link
Copy Markdown
Contributor

Bug

Onboarding step order is:

`1. brand_setup → 2. brand_details → 3. topics → 4. prompts → 5. competitors → 6. plan`

Prompts are saved at step 4 but the plan is only chosen at step 6, so at step 4 the org is still on its `'free'` default (which falls back to Starter limits) and prompts get `platforms: ['chatgpt-web', 'perplexity-web']` baked in. A user who picks a Growth trial at step 6 still ends up tracking only 2 engines instead of the 8 Growth allows.

Fix

In `/api/stripe/success`, right after the org's `plan` / `subscription_status` is confirmed and before the first tracking run is triggered, walk every prompt in the org's brands and rewrite its `platforms` + `models` arrays to match the just-confirmed plan's `allowedScrapers` + `allowedModels`. Same gating logic the onboarding wizard uses, extracted into a small reusable helper.

Files

File Change
`web/src/lib/plan-engines.ts` New `getActiveEngineIdsForPlan(planId)` — mirrors the wizard's `allowedScrapers ? filter : ALL` logic for both scrapers and models. `undefined` allowedScrapers (Growth / Enterprise / Self-hosted) → all 8; explicit array (Starter) → restricted set
`web/src/app/api/stripe/success/route.ts` After the org plan update succeeds, derive engine ids from `getActiveEngineIdsForPlan(planId || 'starter')`, fetch all brand ids in the org, all prompt_set ids in those brands, and bulk-update the prompts. Wrapped in a try/catch so a realignment failure doesn't block the redirect or the tracking trigger that follows

Why a helper, not inline

The same gating shape will be needed for the plan-upgrade engine-expansion gap (separate issue referenced in #78's footer — existing Starter org upgrades to Growth, prompts stay on 2 engines). Centralizing the logic now means that issue is just "call the helper from the subscription-update path" rather than re-deriving the gating in a second place.

Scope guardrails

  • Runs only on `/api/stripe/success` — the initial checkout-success redirect after onboarding. Plan changes / upgrades for existing orgs flow through the subscription update path and stay out of scope for Onboarding creates prompts with only Starter's 2 engines even when a Growth trial is selected #78
  • Starter onboarding is unaffected — for that plan, the new platforms set equals the old one, so the UPDATE is a no-op
  • No-op safe — alignment errors are logged but don't block the redirect or the trigger-tracking call that follows
  • Self-host is unrestricted today — `self_hosted` has no `allowedScrapers`, so all 8 engines apply (consistent with existing policy)

How verified

Local e2e against cloud Stripe test mode:

  1. Reset test account → fresh onboarding state (`onboarding_completed=false`, no org / brand)
  2. Sign-in → step 1 → completed all 6 onboarding steps, selected Growth trial at step 6
  3. Stripe test card → redirected back to `/dashboard/insights`
  4. Server logs:
    ```
    [stripe/success] DB updated for org: ...
    [stripe/success] Aligned prompts to plan=growth engines (8 scrapers, N models) for org ...
    ```
  5. `prompts.platforms` in DB → 8 engine ids; `prompts.models` → Growth's allowed set
  6. `/dashboard/prompts` UI → all 8 platforms shown per prompt
  7. `yarn typecheck` + `yarn format:check` clean

Acceptance (from #78)

  • After completing onboarding with a Growth trial, the created prompts track the engines Growth allows (up to 8), not just 2
  • Starter onboarding behavior is unchanged (2 engines)

Closes #78.

…e success

Onboarding saves prompts at step 4 with the current (pre-checkout, default
Starter) plan's allowedScrapers — `['chatgpt-web', 'perplexity-web']`.
The plan/trial is only chosen at step 6, so a user who starts a Growth
trial still ends up tracking 2 engines instead of the 8 Growth allows.

Fix: in /api/stripe/success, right after the org's plan is confirmed and
before the first tracking run is triggered, walk every prompt in the
org's brands and rewrite its platforms + models arrays to match the
just-confirmed plan's allowedScrapers + allowedModels. Mirrors the same
gating logic the onboarding wizard uses, extracted into a reusable
helper at web/src/lib/plan-engines.ts so the upgrade path (separate
issue) can lean on it too.

Starter onboarding is unaffected — the new platforms set equals the
old one for that plan, so the UPDATE is a no-op. The realignment runs
only on the initial checkout-success redirect, not on existing-org
plan changes (those flow through subscription update and stay out of
scope for #78).

Closes #78.
@gkhngyk
gkhngyk merged commit 16dbc86 into main May 26, 2026
2 checks passed
@gkhngyk
gkhngyk deleted the fix/onboarding-align-prompts-to-plan branch May 26, 2026 16:52

This branch was successfully deployed

1 active deployment
Preview — 28a2a42f Deployed May 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Onboarding creates prompts with only Starter's 2 engines even when a Growth trial is selected

1 participant