From 52650eed1d97a34e772aecc9254973960a84879e Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Tue, 10 Feb 2026 15:43:33 +0100 Subject: [PATCH] refactor(frontend/auth): Move `/copilot` auth check to middleware (#12053) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These "is the user authenticated, and should they be?" checks should not be spread across the codebase, it's complex enough as it is. :') - Follow-up to #12050 ### Changes 🏗️ - Revert "fix(frontend): copilot redirect logout (#12050)" - Add `/copilot` to `PROTECTED_PAGES` in `@/lib/supabase/helpers` ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] Trivial change, we know this works for other pages --- .../frontend/src/app/(platform)/copilot/useCopilotPage.ts | 6 ------ autogpt_platform/frontend/src/lib/supabase/helpers.ts | 1 + 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts index c480ce13b9..3dbba6e790 100644 --- a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts +++ b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts @@ -3,7 +3,6 @@ import { useBreakpoint } from "@/lib/hooks/useBreakpoint"; import { useSupabase } from "@/lib/supabase/hooks/useSupabase"; import { useChat } from "@ai-sdk/react"; import { DefaultChatTransport } from "ai"; -import { useRouter } from "next/navigation"; import { useEffect, useMemo, useState } from "react"; import { useChatSession } from "./useChatSession"; @@ -11,7 +10,6 @@ export function useCopilotPage() { const { isUserLoading, isLoggedIn } = useSupabase(); const [isDrawerOpen, setIsDrawerOpen] = useState(false); const [pendingMessage, setPendingMessage] = useState(null); - const router = useRouter(); const { sessionId, @@ -54,10 +52,6 @@ export function useCopilotPage() { transport: transport ?? undefined, }); - useEffect(() => { - if (!isUserLoading && !isLoggedIn) router.replace("/login"); - }, [isUserLoading, isLoggedIn]); - useEffect(() => { if (!hydratedMessages || hydratedMessages.length === 0) return; setMessages((prev) => { diff --git a/autogpt_platform/frontend/src/lib/supabase/helpers.ts b/autogpt_platform/frontend/src/lib/supabase/helpers.ts index 26f7711bde..c77e43e7b4 100644 --- a/autogpt_platform/frontend/src/lib/supabase/helpers.ts +++ b/autogpt_platform/frontend/src/lib/supabase/helpers.ts @@ -6,6 +6,7 @@ import { SupabaseClient } from "@supabase/supabase-js"; export const PROTECTED_PAGES = [ "/auth/authorize", "/auth/integrations", + "/copilot", "/monitor", "/build", "/onboarding",