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): send signed-in and onboarded users straight to /home (#15155)
Reinier van der Leer6ac55f2ac555
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/login/__tests__/actions.test.ts b/autogpt_platform/frontend/src/app/(no-navbar)/login/__tests__/actions.test.tsindex b42ed541b3..59e2f05968 100644--- a/autogpt_platform/frontend/src/app/(no-navbar)/login/__tests__/actions.test.ts+++ b/autogpt_platform/frontend/src/app/(no-navbar)/login/__tests__/actions.test.ts@@ -97,14 +97,14 @@ describe("login", () => {expect(result).toEqual({ success: true, next: "/onboarding" });});- it("sends returning users to copilot when onboarding is already complete", async () => {+ it("sends returning users to /home when onboarding is already complete", async () => {signInEmailMock.mockResolvedValue({ user: { id: "user-1" } });createUserMock.mockResolvedValue(userResponse(false));getOnboardingStatusMock.mockResolvedValue({ shouldShowOnboarding: false });const result = await login("[email protected]", "hunter2-password");- expect(result).toEqual({ success: true, next: "/copilot" });+ expect(result).toEqual({ success: true, next: "/home" });});it("returns the Better Auth error message when sign-in fails with an APIError", async () => {@@ -192,7 +192,7 @@ describe("login", () => {const result = await login("[email protected]", "hunter2-password");expect(rollbackSessionMock).not.toHaveBeenCalled();- expect(result).toEqual({ success: true, next: "/copilot" });+ expect(result).toEqual({ success: true, next: "/home" });});it("counts the sign-up when this login is the call that created the account", async () => {diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/login/actions.ts b/autogpt_platform/frontend/src/app/(no-navbar)/login/actions.tsindex 31984cfb76..395bb99063 100644--- a/autogpt_platform/frontend/src/app/(no-navbar)/login/actions.ts+++ b/autogpt_platform/frontend/src/app/(no-navbar)/login/actions.ts@@ -84,7 +84,7 @@ export async function login(return {success: true,- next: shouldShowOnboarding ? "/onboarding" : "/copilot",+ next: shouldShowOnboarding ? "/onboarding" : "/home",};} catch (err) {Sentry.captureException(err);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.tsxindex a0aa0ca7bb..b253540d9f 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@@ -532,12 +532,12 @@ describe("OnboardingPage — flag-gated SubscriptionStep", () => {expect(submitOnboardingProfile).not.toHaveBeenCalled();});- it("redirects straight to /copilot when onboarding is already complete", async () => {+ it("redirects straight to /home when onboarding is already complete", async () => {mockCompletedSteps = ["ONBOARDING_COMPLETE"];window.sessionStorage.setItem(STEP_STORAGE_KEY, "3");render(<OnboardingPage />);await waitFor(() => {- expect(routerReplace).toHaveBeenCalledWith("/copilot");+ expect(routerReplace).toHaveBeenCalledWith("/home");});// The wizard never renders and the resume ceiling is cleared.expect(screen.queryByTestId("step-role")).toBeNull();@@ -551,7 +551,7 @@ describe("OnboardingPage — flag-gated SubscriptionStep", () => {render(<OnboardingPage />);fireEvent.click(await screen.findByTestId("step-preparing"));await waitFor(() => {- expect(routerReplace).toHaveBeenCalledWith("/copilot");+ expect(routerReplace).toHaveBeenCalledWith("/home");});expect(completeOnboardingStep).toHaveBeenCalledWith({step: "ONBOARDING_COMPLETE",@@ -572,7 +572,7 @@ describe("OnboardingPage — flag-gated SubscriptionStep", () => {render(<OnboardingPage />);fireEvent.click(await screen.findByTestId("step-preparing"));await waitFor(() => {- expect(routerReplace).toHaveBeenCalledWith("/copilot");+ expect(routerReplace).toHaveBeenCalledWith("/home");});expect(gtagCalls).toContainEqual([@@ -589,7 +589,7 @@ describe("OnboardingPage — flag-gated SubscriptionStep", () => {"onboarding_complete=OC",);const gtagCalls = installGtagShim();- // All three attempts fail: the user still lands on the copilot, but the+ // All three attempts fail: the user still lands on /home, but the// backend never recorded the milestone, so nothing converted.completeOnboardingStep.mockRejectedValue(new Error("500"));mockFlagValue = false;@@ -599,7 +599,7 @@ describe("OnboardingPage — flag-gated SubscriptionStep", () => {fireEvent.click(await screen.findByTestId("step-preparing"));await waitFor(() => {- expect(routerReplace).toHaveBeenCalledWith("/copilot");+ expect(routerReplace).toHaveBeenCalledWith("/home");},{ timeout: 5000 },);diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.tsindex fa26953882..32f52f64cb 100644--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts@@ -217,7 +217,7 @@ export function useOnboardingPage() {// Report the step the wizard is actually showing. `isOnboardingStateLoading`// is the same gate the page renders on — it also covers the window holding- // the ONBOARDING_COMPLETE check that redirects finished users to /copilot —+ // the ONBOARDING_COMPLETE check that redirects finished users to /home —// and `isStepSettled` means the step above has landed, so a user resuming// at Preparing never reports the store's default of Welcome on the way past.// Repeat visits to a step are dropped by `trackOnboardingStep` itself, so@@ -251,11 +251,11 @@ export function useOnboardingPage() {clearHighestStep();// Clear the persisted form data without touching in-memory state.// `reset()` would set currentStep=1 and trip the URL-sync effect- // into racing with the /copilot redirect (the spurious+ // into racing with the /home redirect (the spurious// /onboarding?step=1 replace wins, stranding the user on Welcome// until they refresh).useOnboardingWizardStore.persist.clearStorage();- router.replace("/copilot");+ router.replace("/home");return;}} catch {@@ -303,7 +303,7 @@ export function useOnboardingPage() {});clearHighestStep();useOnboardingWizardStore.persist.clearStorage();- router.replace("/copilot");+ router.replace("/home");return;} catch {if (attempt < 2) await new Promise((r) => setTimeout(r, 1000));@@ -311,7 +311,7 @@ export function useOnboardingPage() {}clearHighestStep();useOnboardingWizardStore.persist.clearStorage();- router.replace("/copilot");+ router.replace("/home");}return {diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/signup/__tests__/signup-action.test.ts b/autogpt_platform/frontend/src/app/(no-navbar)/signup/__tests__/signup-action.test.tsindex 59442a36bb..18d9f7c9d6 100644--- a/autogpt_platform/frontend/src/app/(no-navbar)/signup/__tests__/signup-action.test.ts+++ b/autogpt_platform/frontend/src/app/(no-navbar)/signup/__tests__/signup-action.test.ts@@ -105,7 +105,7 @@ describe("signup", () => {expect(result).toEqual({ success: true, next: "/onboarding" });});- it("routes straight to copilot when onboarding is already complete", async () => {+ it("routes straight to /home when onboarding is already complete", async () => {signUpEmailMock.mockResolvedValue({token: "session-token",user: { id: "user-1" },@@ -118,7 +118,7 @@ describe("signup", () => {const result = await signupWithValidPayload();- expect(result).toEqual({ success: true, next: "/copilot" });+ expect(result).toEqual({ success: true, next: "/home" });});it("reports user_already_exists when Better Auth rejects a duplicate email", async () => {diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/signup/actions.ts b/autogpt_platform/frontend/src/app/(no-navbar)/signup/actions.tsindex c6f1eb51e4..6dbfd4b584 100644--- a/autogpt_platform/frontend/src/app/(no-navbar)/signup/actions.ts+++ b/autogpt_platform/frontend/src/app/(no-navbar)/signup/actions.ts@@ -112,7 +112,7 @@ export async function signup(return {success: true,- next: shouldShowOnboarding ? "/onboarding" : "/copilot",+ next: shouldShowOnboarding ? "/onboarding" : "/home",};} catch (err) {Sentry.captureException(err);diff --git a/autogpt_platform/frontend/src/lib/auth-redirect.test.ts b/autogpt_platform/frontend/src/lib/auth-redirect.test.tsindex 788453cfce..db5a4dceed 100644--- a/autogpt_platform/frontend/src/lib/auth-redirect.test.ts+++ b/autogpt_platform/frontend/src/lib/auth-redirect.test.ts@@ -28,10 +28,31 @@ describe("sanitizeAuthNext", () => {test("accepts same-origin relative paths verbatim", () => {expect(sanitizeAuthNext("/library")).toBe("/library");expect(sanitizeAuthNext("/onboarding?step=2")).toBe("/onboarding?step=2");- expect(sanitizeAuthNext("/copilot#section")).toBe("/copilot#section");+ expect(sanitizeAuthNext("/library#section")).toBe("/library#section");expect(sanitizeAuthNext("/")).toBe("/");});+ // /copilot is only a server redirect to /home, and a client navigation into it+ // from a (no-navbar) page crashes the App Router with React #310.+ test.each([+ ["/copilot", "/home"],+ ["/copilot/", "/home"],+ ["/copilot?sessionId=abc", "/home?sessionId=abc"],+ ["/copilot#frag", "/home#frag"],+ ["/copilot/?sessionId=abc#frag", "/home?sessionId=abc#frag"],+ ])("maps %s to %s so the redirect hop is skipped", (value, expected) => {+ expect(sanitizeAuthNext(value)).toBe(expected);+ });++ test.each([+ "/copilots",+ "/copilot/styleguide",+ "/home",+ "/home?sessionId=abc",+ ])("leaves %s untouched", (value) => {+ expect(sanitizeAuthNext(value)).toBe(value);+ });+// Everything below resolves off-origin through the WHATWG URL parser, which// is what window.location.href and NextResponse.redirect both use. Each case// passes a naive startsWith("/") && !startsWith("//") check, so they are thediff --git a/autogpt_platform/frontend/src/lib/auth-redirect.ts b/autogpt_platform/frontend/src/lib/auth-redirect.tsindex 94c398689b..772a7e866a 100644--- a/autogpt_platform/frontend/src/lib/auth-redirect.ts+++ b/autogpt_platform/frontend/src/lib/auth-redirect.ts@@ -27,5 +27,7 @@ export function sanitizeAuthNext(// could slip past the checks above and then resolve as "//evil.com".// eslint-disable-next-line no-control-regexif (/[\u0000-\u001F\u007F]/.test(rawNext)) return null;- return rawNext;+ // /copilot is only a server redirect to /home; a client navigation into that+ // redirect from a (no-navbar) page crashes the App Router (React #310).+ return rawNext.replace(/^\/copilot\/?(?=[?#]|$)/, "/home");}diff --git a/autogpt_platform/frontend/src/playwright/auth-happy-path.spec.ts b/autogpt_platform/frontend/src/playwright/auth-happy-path.spec.tsindex 749a30330a..72209a21a3 100644--- a/autogpt_platform/frontend/src/playwright/auth-happy-path.spec.ts+++ b/autogpt_platform/frontend/src/playwright/auth-happy-path.spec.ts@@ -2,11 +2,7 @@ import { expect, test } from "./coverage-fixture";import { getSeededTestUser } from "./credentials/accounts";import { BuildPage } from "./pages/build.page";import { LoginPage } from "./pages/login.page";-import {- completeOnboardingWizard,- advanceToRoleStep,- skipOnboardingIfPresent,-} from "./utils/onboarding";+import { advanceToRoleStep, skipOnboardingIfPresent } from "./utils/onboarding";import { signupTestUser } from "./utils/signup";test("auth happy path: user can sign up with a fresh account", async ({@@ -77,23 +73,6 @@ test("auth happy path: seeded user can log out and protected routes redirect toawait expect(page).toHaveURL(/\/login\?next=%2Fprofile/);});-test("auth happy path: user can complete onboarding and land in the app", async ({- page,-}) => {- test.setTimeout(60000);-- await signupTestUser(page, undefined, undefined, false);- await expect(page).toHaveURL(/\/onboarding/);-- await completeOnboardingWizard(page, {- role: "Engineering",- painPoints: ["Research", "Reports & data"],- });-- await expect(page).toHaveURL(/\/home/);- await expect(page.getByTestId("profile-popout-menu-trigger")).toBeVisible();-});-test("auth happy path: multi-tab logout clears shared builder sessions", async ({context,}) => {diff --git a/autogpt_platform/frontend/src/playwright/landing-happy-path.spec.ts b/autogpt_platform/frontend/src/playwright/landing-happy-path.spec.tsnew file mode 100644index 0000000000..b88949c349--- /dev/null+++ b/autogpt_platform/frontend/src/playwright/landing-happy-path.spec.ts@@ -0,0 +1,61 @@+import type { Page } from "@playwright/test";+import { expect, test } from "./coverage-fixture";+import { getSeededTestUser } from "./credentials/accounts";+import { LoginPage } from "./pages/login.page";+import { completeOnboardingWizard } from "./utils/onboarding";+import { signupTestUser } from "./utils/signup";++test("landing happy path: a signed-in user opening /login lands on /home", async ({+ page,+}) => {+ test.setTimeout(60000);++ const copilotRequests = recordCopilotNavigations(page);+ const testUser = getSeededTestUser("smokeAuth");+ await page.goto("/login");+ await new LoginPage(page).login(testUser.email, testUser.password);++ await page.goto("/login");++ await expectHomeLanding(page, copilotRequests);+});++test("landing happy path: a user finishing onboarding lands on /home", async ({+ page,+}) => {+ test.setTimeout(60000);++ await signupTestUser(page, undefined, undefined, false);+ await expect(page).toHaveURL(/\/onboarding/);++ const copilotRequests = recordCopilotNavigations(page);+ await completeOnboardingWizard(page, {+ role: "Engineering",+ painPoints: ["Research", "Reports & data"],+ });++ await expectHomeLanding(page, copilotRequests);+});++async function expectHomeLanding(page: Page, copilotRequests: string[]) {+ await expect(page).toHaveURL(/\/home(\?|$)/, { timeout: 30000 });+ await expect(page.getByTestId("profile-popout-menu-trigger")).toBeVisible();+ await expect(page.getByText("Application error")).toHaveCount(0);+ // /copilot only redirects to /home; entering it from these pages crashed Next's router on Vercel.+ expect(copilotRequests).toEqual([]);+}++function recordCopilotNavigations(page: Page): string[] {+ const requests: string[] = [];+ page.on("request", (request) => {+ const headers = request.headers();+ if (+ new URL(request.url()).pathname === "/copilot" &&+ !headers["next-router-prefetch"] &&+ !headers["next-router-segment-prefetch"]+ ) {+ requests.push(request.url());+ }+ });+ return requests;+}diff --git a/autogpt_platform/frontend/src/providers/onboarding/__tests__/onboarding-provider-routing.test.tsx b/autogpt_platform/frontend/src/providers/onboarding/__tests__/onboarding-provider-routing.test.tsxindex 6c5bdceca1..24c9cf1c6e 100644--- a/autogpt_platform/frontend/src/providers/onboarding/__tests__/onboarding-provider-routing.test.tsx+++ b/autogpt_platform/frontend/src/providers/onboarding/__tests__/onboarding-provider-routing.test.tsx@@ -145,7 +145,7 @@ describe("OnboardingProvider routing — logged-in user", () => {);});- test("completed user on /signup is redirected to /copilot", async () => {+ test("completed user on /signup is redirected to /home", async () => {mockPathname = "/signup";mockIsCompleted = true;@@ -155,10 +155,10 @@ describe("OnboardingProvider routing — logged-in user", () => {</OnboardingProvider>,);- await waitFor(() => expect(routerReplace).toHaveBeenCalledWith("/copilot"));+ await waitFor(() => expect(routerReplace).toHaveBeenCalledWith("/home"));});- test("completed user on /login is redirected to /copilot", async () => {+ test("completed user on /login is redirected to /home", async () => {mockPathname = "/login";mockIsCompleted = true;@@ -168,7 +168,7 @@ describe("OnboardingProvider routing — logged-in user", () => {</OnboardingProvider>,);- await waitFor(() => expect(routerReplace).toHaveBeenCalledWith("/copilot"));+ await waitFor(() => expect(routerReplace).toHaveBeenCalledWith("/home"));});test("a safe ?next= deep link defers to the auth page — no redirect from provider", async () => {diff --git a/autogpt_platform/frontend/src/providers/onboarding/helpers.test.ts b/autogpt_platform/frontend/src/providers/onboarding/helpers.test.tsindex b1db9aa580..42806d4eff 100644--- a/autogpt_platform/frontend/src/providers/onboarding/helpers.test.ts+++ b/autogpt_platform/frontend/src/providers/onboarding/helpers.test.ts@@ -68,24 +68,24 @@ describe("decideOnboardingRedirect", () => {).toBeNull();});- test("completed user on /onboarding is sent to /copilot", () => {+ test("completed user on /onboarding is sent to /home", () => {expect(decideOnboardingRedirect({...base,isCompleted: true,isOnOnboardingRoute: true,}),- ).toBe("/copilot");+ ).toBe("/home");});- test("completed user on /signup or /login is sent to /copilot", () => {+ test("completed user on /signup or /login is sent to /home", () => {expect(decideOnboardingRedirect({...base,isCompleted: true,isOnAuthRoute: true,}),- ).toBe("/copilot");+ ).toBe("/home");});test("completed user already on the product is left alone", () => {diff --git a/autogpt_platform/frontend/src/providers/onboarding/helpers.ts b/autogpt_platform/frontend/src/providers/onboarding/helpers.tsindex 894ce3fc2a..59a6d1da71 100644--- a/autogpt_platform/frontend/src/providers/onboarding/helpers.ts+++ b/autogpt_platform/frontend/src/providers/onboarding/helpers.ts@@ -68,10 +68,10 @@ export function decideOnboardingRedirect({isOnOnboardingRoute: boolean;isOnAuthRoute: boolean;hasPendingAuthDeepLink: boolean;-}): "/onboarding" | "/copilot" | null {+}): "/onboarding" | "/home" | null {if (hasPendingAuthDeepLink) return null;if (!isCompleted && !isOnOnboardingRoute) return "/onboarding";- if (isCompleted && (isOnOnboardingRoute || isOnAuthRoute)) return "/copilot";+ if (isCompleted && (isOnOnboardingRoute || isOnAuthRoute)) return "/home";return null;}diff --git a/autogpt_platform/frontend/src/providers/onboarding/onboarding-provider.tsx b/autogpt_platform/frontend/src/providers/onboarding/onboarding-provider.tsxindex faf1b9600e..322f78939f 100644--- a/autogpt_platform/frontend/src/providers/onboarding/onboarding-provider.tsx+++ b/autogpt_platform/frontend/src/providers/onboarding/onboarding-provider.tsx@@ -203,7 +203,7 @@ export default function OnboardingProvider({isOnOnboardingRoute &&shouldRedirectFromOnboarding(onboarding.completedSteps, pathname)) {- router.replace("/copilot");+ router.replace("/home");}} catch (error) {if (error instanceof ApiError && error.status === 401) {