Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): skip onboarding paywall for users already on a paid tier (#13160)

Ubbe1ed2d421daa4
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/page.test.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/page.test.tsx
index 70d948086e..55c650e1bd 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/page.test.tsx
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/page.test.tsx
@@ -33,8 +33,9 @@ vi.mock("next/navigation", () => ({
usePathname: () => "/onboarding",
}));
+let mockSupabaseState = { isLoggedIn: true, isUserLoading: false };
vi.mock("@/lib/supabase/hooks/useSupabase", () => ({
- useSupabase: () => ({ isLoggedIn: true, isUserLoading: false, user: null }),
+ useSupabase: () => ({ ...mockSupabaseState, user: null }),
}));
vi.mock("@/app/api/__generated__/endpoints/onboarding/onboarding", () => ({
@@ -47,6 +48,19 @@ vi.mock("@/app/api/__generated__/endpoints/onboarding/onboarding", () => ({
postV1SubmitOnboardingProfile: () => Promise.resolve({ status: 200 }),
}));
+let mockSubscriptionTier: string = "NO_TIER";
+vi.mock("@/app/api/__generated__/endpoints/credits/credits", () => ({
+ useGetSubscriptionStatus: (opts: {
+ query: { select: (res: { status: number; data: unknown }) => unknown };
+ }) => ({
+ data: opts.query.select({
+ status: 200,
+ data: { tier: mockSubscriptionTier },
+ }),
+ isLoading: false,
+ }),
+}));
+
vi.mock("@/app/api/helpers", () => ({
resolveResponse: (p: Promise<{ data: unknown }>) => p.then((r) => r.data),
}));
@@ -68,6 +82,8 @@ const STEP_STORAGE_KEY = "autogpt:onboarding-highest-step";
beforeEach(() => {
currentSearchParams = new URLSearchParams();
mockFlagValue = false;
+ mockSubscriptionTier = "NO_TIER";
+ mockSupabaseState = { isLoggedIn: true, isUserLoading: false };
routerReplace.mockClear();
useOnboardingWizardStore.getState().reset();
window.sessionStorage.removeItem(STEP_STORAGE_KEY);
@@ -176,6 +192,65 @@ describe("OnboardingPage — flag-gated SubscriptionStep", () => {
expect(useOnboardingWizardStore.getState().selectedPlan).toBeNull();
});
+ it("skips SubscriptionStep when the user is already on a paid tier", async () => {
+ // Regression for paying users (admin-granted Pro, or accounts that
+ // pre-date VISIT_COPILOT) being kicked through onboarding and asked to
+ // pay again to escape. With ENABLE_PLATFORM_PAYMENT on and tier=PRO,
+ // step 4 must render Preparing — not SubscriptionStep.
+ mockFlagValue = true;
+ mockSubscriptionTier = "PRO";
+ window.sessionStorage.setItem(STEP_STORAGE_KEY, "4");
+ currentSearchParams = new URLSearchParams("step=4");
+ render(<OnboardingPage />);
+ expect(await screen.findByTestId("step-preparing")).toBeDefined();
+ expect(screen.queryByTestId("step-subscription")).toBeNull();
+ });
+
+ it("clamps ?step=5 to preparingStep=4 for paid users", async () => {
+ // For paid users the wizard is 3-step (preparingStep=4). A URL pointing
+ // at the old 5-step preparingStep must clamp down to 4, not strand the
+ // user above the ceiling.
+ mockFlagValue = true;
+ mockSubscriptionTier = "MAX";
+ window.sessionStorage.setItem(STEP_STORAGE_KEY, "5");
+ currentSearchParams = new URLSearchParams("step=5");
+ render(<OnboardingPage />);
+ expect(await screen.findByTestId("step-preparing")).toBeDefined();
+ expect(screen.queryByTestId("step-subscription")).toBeNull();
+ });
+
+ it("still shows SubscriptionStep for NO_TIER users with payments enabled", async () => {
+ mockFlagValue = true;
+ mockSubscriptionTier = "NO_TIER";
+ window.sessionStorage.setItem(STEP_STORAGE_KEY, "4");
+ currentSearchParams = new URLSearchParams("step=4");
+ render(<OnboardingPage />);
+ expect(await screen.findByTestId("step-subscription")).toBeDefined();
+ expect(screen.queryByTestId("step-preparing")).toBeNull();
+ });
+
+ it("waits for Supabase auth before initialising (no premature step lock)", async () => {
+ // Regression: LD can resolve while auth is still loading. Without
+ // gating on isUserLoading, isReady flips true (the !isLoggedIn branch
+ // short-circuits), init runs against the pre-tier preparingStep (5)
+ // and a returning user with highestStep=5 lands on currentStep=5.
+ // When tier resolves to PRO, preparingStep becomes 4 — but the
+ // hasInitialized guard blocks re-init, leaving currentStep=5 with
+ // no matching step guard (blank page).
+ mockFlagValue = true;
+ mockSubscriptionTier = "PRO";
+ mockSupabaseState = { isLoggedIn: false, isUserLoading: true };
+ window.sessionStorage.setItem(STEP_STORAGE_KEY, "5");
+ render(<OnboardingPage />);
+ // Nothing should render while auth is still loading.
+ expect(screen.queryByTestId("step-welcome")).toBeNull();
+ expect(screen.queryByTestId("step-preparing")).toBeNull();
+ expect(screen.queryByTestId("step-subscription")).toBeNull();
+ // After init defers (auth not ready), currentStep stays at the
+ // store default of 1 — no premature jump to 5.
+ expect(useOnboardingWizardStore.getState().currentStep).toBe(1);
+ });
+
it("preserves form data on mount (zustand persist; no reset-on-init)", async () => {
// Regression test for the 422 caused by init's old `reset()` wiping
// name/role on every mount. With zustand persist, refreshing mid-wizard
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts
index 1aa9ba8e5d..a92abd7f89 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts
@@ -1,8 +1,10 @@
+import { useGetSubscriptionStatus } from "@/app/api/__generated__/endpoints/credits/credits";
import {
getV1OnboardingState,
postV1CompleteOnboardingStep,
postV1SubmitOnboardingProfile,
} from "@/app/api/__generated__/endpoints/onboarding/onboarding";
+import type { SubscriptionStatusResponse } from "@/app/api/__generated__/models/subscriptionStatusResponse";
import { resolveResponse } from "@/app/api/helpers";
import { useSupabase } from "@/lib/supabase/hooks/useSupabase";
import { environment } from "@/services/environment";
@@ -47,7 +49,7 @@ function clearHighestStep() {
export function useOnboardingPage() {
const router = useRouter();
const searchParams = useSearchParams();
- const { isLoggedIn } = useSupabase();
+ const { isLoggedIn, isUserLoading } = useSupabase();
const currentStep = useOnboardingWizardStore((s) => s.currentStep);
const goToStep = useOnboardingWizardStore((s) => s.goToStep);
@@ -84,10 +86,31 @@ export function useOnboardingPage() {
if (paymentEnabledSnapshot.current === null && areFlagsReady) {
paymentEnabledSnapshot.current = livePaymentEnabled;
}
- const isPaymentEnabled = paymentEnabledSnapshot.current ?? false;
+
+ // Skip the paywall for users already on a paid tier (admin grants or
+ // pre-VISIT_COPILOT accounts) so they aren't asked to pay again to escape.
+ const { data: tier, isLoading: isTierLoading } = useGetSubscriptionStatus({
+ query: {
+ enabled: isLoggedIn,
+ select: (res) =>
+ res.status === 200
+ ? (res.data as SubscriptionStatusResponse).tier
+ : null,
+ },
+ });
+ const userHasActivePlan = !!tier && tier !== "NO_TIER";
+
+ const isPaymentEnabled =
+ (paymentEnabledSnapshot.current ?? false) && !userHasActivePlan;
const preparingStep: Step = isPaymentEnabled ? 5 : 4;
const totalSteps = isPaymentEnabled ? 4 : 3;
+ // Wait for auth too — without !isUserLoading, LD can resolve while
+ // isLoggedIn is transiently false, the tier query stays disabled
+ // (isTierLoading=false), and init fires with the wrong preparingStep.
+ const isReady =
+ areFlagsReady && !isUserLoading && (!isLoggedIn || !isTierLoading);
+
const [isOnboardingStateLoading, setIsOnboardingStateLoading] =
useState(true);
const hasSubmitted = useRef(false);
@@ -100,7 +123,7 @@ export function useOnboardingPage() {
// would defeat the point of persistence by wiping the user's name/role
// every time they refresh mid-wizard.
useEffect(() => {
- if (!areFlagsReady || hasInitialized.current) return;
+ if (!isReady || hasInitialized.current) return;
hasInitialized.current = true;
const urlStep = parseStepParam(searchParams.get("step"), preparingStep);
// A successful Stripe checkout return is a trusted intent to advance to
@@ -115,11 +138,11 @@ export function useOnboardingPage() {
urlStep === null ? ceiling : Math.min(urlStep, ceiling)
) as Step;
goToStep(target);
- }, [areFlagsReady, searchParams, goToStep, preparingStep]);
+ }, [isReady, searchParams, goToStep, preparingStep]);
// Sync store → URL when step changes; record the new ceiling.
useEffect(() => {
- if (!areFlagsReady) return;
+ if (!isReady) return;
const urlStep = parseStepParam(searchParams.get("step"), preparingStep);
if (currentStep !== urlStep) {
router.replace(`/onboarding?step=${currentStep}`, { scroll: false });
@@ -127,7 +150,7 @@ export function useOnboardingPage() {
if (currentStep > readHighestStep()) {
writeHighestStep(currentStep);
}
- }, [areFlagsReady, currentStep, router, searchParams, preparingStep]);
+ }, [isReady, currentStep, router, searchParams, preparingStep]);
// Check if onboarding already completed
useEffect(() => {
@@ -203,7 +226,7 @@ export function useOnboardingPage() {
return {
currentStep,
- isLoading: isOnboardingStateLoading || !areFlagsReady,
+ isLoading: isOnboardingStateLoading || !isReady,
handlePreparingComplete,
isPaymentEnabled,
preparingStep,