From 149589ae7e6b72a5be57ddb052a41f3eee0e7614 Mon Sep 17 00:00:00 2001 From: MaheshtheDev <38828053+MaheshtheDev@users.noreply.github.com> Date: Tue, 18 Aug 2026 23:13:12 +0000 Subject: [PATCH] fix(brain): keep the confirmed company domain after checkout return (#1536) Returning from Stripe remounts onboarding and reseeds the domain from the user's email, so the header showed the wrong company and a research retry would re-run on the wrong domain. Past the confirm step, read the org's stored brainWorkspaceDomain instead. --- .../onboarding-brain/company-brain-onboarding.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/web/components/onboarding-brain/company-brain-onboarding.tsx b/apps/web/components/onboarding-brain/company-brain-onboarding.tsx index 3d69acb7..61b0cddd 100644 --- a/apps/web/components/onboarding-brain/company-brain-onboarding.tsx +++ b/apps/web/components/onboarding-brain/company-brain-onboarding.tsx @@ -3,6 +3,7 @@ import { LogoFull } from "@ui/assets/Logo" import { Button } from "@ui/components/button" import { Input } from "@ui/components/input" +import { useAuth } from "@lib/auth-context" import { cn } from "@lib/utils" import { ArrowRight, @@ -15,6 +16,7 @@ import { import { useQuery, useQueryClient } from "@tanstack/react-query" import { AnimatePresence, motion } from "motion/react" import { type ReactNode, useEffect, useRef, useState } from "react" +import { getBrainWorkspaceDomain } from "@/lib/billing-utils" import { dmSans125ClassName, dmSansClassName } from "@/lib/fonts" import { type ResearchEvent, @@ -102,13 +104,19 @@ export function CompanyBrainOnboarding({ setPhase("trial") analytics.brainTrialCardViewed() }, [needsSetup, phase]) + const { org } = useAuth() const [domain, setDomain] = useState(initialDomain) const [organizationChoices, setOrganizationChoices] = useState< CompanyBrainOrganizationChoice[] | null >(null) const [serverSchedulesResearch, setServerSchedulesResearch] = useState(false) const firstName = name.trim().split(/\s+/)[0] ?? "" - const clean = normalizeDomain(domain) + // Returning from checkout remounts and reseeds local state from the email domain, + // so past the confirm step the org's stored domain is the one to trust. + const confirmedDomain = getBrainWorkspaceDomain(org?.metadata) + const clean = normalizeDomain( + phase === "confirm" ? domain : confirmedDomain || domain, + ) const queryClient = useQueryClient() const { status: researchStatus } = useResearchStatus(phase === "research") const researchDone = researchStatus === "done"