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): route paywall logout through shared /logout page (#13307)

Ubbe28d04ccf72c7
diff --git a/autogpt_platform/frontend/src/app/(platform)/PaywallGate/PaywallGate.tsx b/autogpt_platform/frontend/src/app/(platform)/PaywallGate/PaywallGate.tsx
index 2fa557ac8d..8fa73d13aa 100644
--- a/autogpt_platform/frontend/src/app/(platform)/PaywallGate/PaywallGate.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/PaywallGate/PaywallGate.tsx
@@ -5,6 +5,7 @@ import { usePathname } from "next/navigation";
import { useGetSubscriptionStatus } from "@/app/api/__generated__/endpoints/credits/credits";
import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
import { environment } from "@/services/environment";
+import { useSupabase } from "@/lib/supabase/hooks/useSupabase";
import { PaywallModal } from "./PaywallModal";
// Routes that bypass the paywall regardless of subscription state — primarily
@@ -25,6 +26,7 @@ const PAYWALL_EXEMPT_PREFIXES = [
export function PaywallGate({ children }: { children: ReactNode }) {
const pathname = usePathname();
+ const { isLoggedIn } = useSupabase();
const isPaymentEnabled = useGetFlag(Flag.ENABLE_PLATFORM_PAYMENT);
const { data: subscription, isLoading } = useGetSubscriptionStatus({
query: {
@@ -44,6 +46,10 @@ export function PaywallGate({ children }: { children: ReactNode }) {
// change land on NO_TIER (the explicit "no active subscription" state).
const shouldGate =
!!isPaymentEnabled &&
+ // Never gate a logged-out user — they're on their way to /login (e.g. via
+ // the modal's own Log out button), and the modal must not linger or block
+ // that exit.
+ isLoggedIn &&
!isLoading &&
!isExempt &&
// Never gate local dev — running the stack locally shouldn't require a
diff --git a/autogpt_platform/frontend/src/app/(platform)/PaywallGate/__tests__/PaywallGate.test.tsx b/autogpt_platform/frontend/src/app/(platform)/PaywallGate/__tests__/PaywallGate.test.tsx
index 799e8079f2..82fa992e32 100644
--- a/autogpt_platform/frontend/src/app/(platform)/PaywallGate/__tests__/PaywallGate.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/PaywallGate/__tests__/PaywallGate.test.tsx
@@ -8,6 +8,12 @@ vi.mock("next/navigation", () => ({
useRouter: () => ({ replace: vi.fn() }),
}));
+// Mock the auth hook — toggle logged-in vs logged-out per test.
+let mockIsLoggedIn = true;
+vi.mock("@/lib/supabase/hooks/useSupabase", () => ({
+ useSupabase: () => ({ isLoggedIn: mockIsLoggedIn }),
+}));
+
// Mock the LD flag hook — toggle paid-cohort vs beta-cohort per test.
let mockIsPaymentEnabled: boolean | undefined = false;
vi.mock("@/services/feature-flags/use-get-flag", () => ({
@@ -45,6 +51,7 @@ import { PaywallGate } from "../PaywallGate";
describe("PaywallGate", () => {
beforeEach(() => {
mockPathname = "/build";
+ mockIsLoggedIn = true;
mockIsPaymentEnabled = false;
mockSubscriptionResult = { data: null, isLoading: false };
mockIsLocal = false;
@@ -74,6 +81,19 @@ describe("PaywallGate", () => {
expect(screen.getByTestId("paywall-modal")).toBeDefined();
});
+ it("does not render modal once the user is logged out, even when paid cohort + tier is NO_TIER", () => {
+ mockIsPaymentEnabled = true;
+ mockIsLoggedIn = false;
+ mockSubscriptionResult = { data: { tier: "NO_TIER" }, isLoading: false };
+ render(
+ <PaywallGate>
+ <div>protected</div>
+ </PaywallGate>,
+ );
+ expect(screen.getByText("protected")).toBeDefined();
+ expect(screen.queryByTestId("paywall-modal")).toBeNull();
+ });
+
it("does not render modal in local dev even when paid cohort + tier is NO_TIER", () => {
mockIsPaymentEnabled = true;
mockIsLocal = true;
diff --git a/autogpt_platform/frontend/src/app/(platform)/PaywallGate/__tests__/PaywallModal.test.tsx b/autogpt_platform/frontend/src/app/(platform)/PaywallGate/__tests__/PaywallModal.test.tsx
index eb6f2129e8..20daec88c1 100644
--- a/autogpt_platform/frontend/src/app/(platform)/PaywallGate/__tests__/PaywallModal.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/PaywallGate/__tests__/PaywallModal.test.tsx
@@ -39,9 +39,19 @@ vi.mock("@/components/molecules/Dialog/Dialog", () => ({
Dialog: MockDialog,
}));
-const mockLogOut = vi.fn();
-vi.mock("@/lib/supabase/hooks/useSupabase", () => ({
- useSupabase: () => ({ logOut: mockLogOut }),
+const mockReplace = vi.fn();
+vi.mock("next/navigation", () => ({
+ useRouter: () => ({
+ push: vi.fn(),
+ replace: mockReplace,
+ prefetch: vi.fn(),
+ back: vi.fn(),
+ forward: vi.fn(),
+ refresh: vi.fn(),
+ }),
+ usePathname: () => "/build",
+ useSearchParams: () => new URLSearchParams(),
+ useParams: () => ({}),
}));
import { PaywallModal } from "../PaywallModal";
@@ -137,7 +147,7 @@ describe("PaywallModal — dynamic plan rendering", () => {
});
describe("PaywallModal — logout", () => {
- it("logs out when the Log out button is clicked", () => {
+ it("routes to the shared /logout page when the Log out button is clicked", () => {
setupMocks({
subscription: { tier: "NO_TIER", tier_costs: { PRO: 5000 } },
});
@@ -146,7 +156,7 @@ describe("PaywallModal — logout", () => {
fireEvent.click(screen.getByRole("button", { name: /log out/i }));
- expect(mockLogOut).toHaveBeenCalled();
+ expect(mockReplace).toHaveBeenCalledWith("/logout");
});
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/PaywallGate/usePaywallModal.ts b/autogpt_platform/frontend/src/app/(platform)/PaywallGate/usePaywallModal.ts
index b7747a0b89..02256fed23 100644
--- a/autogpt_platform/frontend/src/app/(platform)/PaywallGate/usePaywallModal.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/PaywallGate/usePaywallModal.ts
@@ -1,12 +1,12 @@
"use client";
import { useState } from "react";
+import { useRouter } from "next/navigation";
import {
useGetSubscriptionStatus,
useUpdateSubscriptionTier,
} from "@/app/api/__generated__/endpoints/credits/credits";
import type { SubscriptionTierRequestTier } from "@/app/api/__generated__/models/subscriptionTierRequestTier";
-import { useSupabase } from "@/lib/supabase/hooks/useSupabase";
import { toast } from "@/components/molecules/Toast/use-toast";
import { COUNTRIES } from "@/components/molecules/PlanCard/countries";
import {
@@ -55,7 +55,7 @@ export function usePaywallModal() {
query: { select: (res) => (res.status === 200 ? res.data : null) },
});
const { mutateAsync: updateTier, isPending } = useUpdateSubscriptionTier();
- const { logOut } = useSupabase();
+ const router = useRouter();
const [selectedCycle, setSelectedCycle] = useState<"monthly" | "yearly">(
"yearly",
);
@@ -140,8 +140,12 @@ export function usePaywallModal() {
setPendingTier(null);
}
+ // Route through the shared /logout page (same path the Navbar uses) rather
+ // than calling logOut() inline: it runs the full sign-out, then redirects to
+ // /login. Navigating away also unmounts this modal — without the redirect the
+ // user would be left logged-out but stranded behind the paywall.
function handleLogout() {
- void logOut();
+ router.replace("/logout");
}
const pendingTierLabel = pendingTier