Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(onboarding): legacy user calls, stripe checkout (#5229)
teo8bf40a66263e
diff --git a/apps/web/src/features/auth/Login.tsx b/apps/web/src/features/auth/Login.tsxindex 6475e2a077..63811a386c 100644--- a/apps/web/src/features/auth/Login.tsx+++ b/apps/web/src/features/auth/Login.tsx@@ -8,18 +8,17 @@ import { virtualKeyboardVisible } from '@core/mobile/virtualKeyboard';import { unsetTokenPromise } from '@core/util/fetchWithToken';import LogoIcon from '@icon/macro-logo.svg';import { useUserInfo } from '@queries/auth';-import {- invalidateAllAfterLogin,- invalidateUserInfo,-} from '@queries/auth/user-info';+import { invalidateAllAfterLogin } from '@queries/auth/user-info';import { authServiceClient } from '@service-auth/client';import { useNavigate, useSearchParams } from '@solidjs/router';import { cn, Surface } from '@ui';import { detect } from 'detect-browser';import {createEffect,+ createMemo,createSignal,Match,+ on,onCleanup,onMount,Show,@@ -60,6 +59,10 @@ function LoginOld() {const userInfo = useUserInfo();const [searchParams] = useSearchParams();const analytics = useAnalytics();+ const authenticatedUserId = createMemo(() => {+ const user = userInfo();+ return user?.authenticated ? user.id : undefined;+ });onMount(() => {analytics.pageView('login');@@ -77,11 +80,11 @@ function LoginOld() {});};- createEffect(() => {- if (userInfo()?.authenticated) {- invalidateUserInfo().then(identifyUser);- }- });+ createEffect(+ on(authenticatedUserId, (userId) => {+ if (userId) identifyUser();+ })+ );createEffect(() => {if (searchParams.email) {diff --git a/apps/web/src/features/auth/LoginNew.tsx b/apps/web/src/features/auth/LoginNew.tsxindex 71781d5683..14d49e088f 100644--- a/apps/web/src/features/auth/LoginNew.tsx+++ b/apps/web/src/features/auth/LoginNew.tsx@@ -19,7 +19,6 @@ import ArrowRight from '@phosphor/arrow-right.svg';import { useUserInfo } from '@queries/auth';import {invalidateAllAfterLogin,- invalidateUserInfo,useUserInfoQuery,} from '@queries/auth/user-info';import { authServiceClient } from '@service-auth/client';@@ -35,8 +34,10 @@ import { Stepper } from '@ui/components/Stepper';import { detect } from 'detect-browser';import {createEffect,+ createMemo,createSignal,type JSX,+ on,onCleanup,onMount,Show,@@ -433,6 +434,10 @@ export function LoginNew() {);const userInfo = useUserInfo();const analytics = useAnalytics();+ const authenticatedUserId = createMemo(() => {+ const user = userInfo();+ return user?.authenticated ? user.id : undefined;+ });onMount(() => {analytics.pageView('login');@@ -450,11 +455,11 @@ export function LoginNew() {});};- createEffect(() => {- if (userInfo()?.authenticated) {- invalidateUserInfo().then(identifyUser);- }- });+ createEffect(+ on(authenticatedUserId, (userId) => {+ if (userId) identifyUser();+ })+ );createEffect(() => {// token may be an array if the redirect URL contained duplicate token params;diff --git a/apps/web/src/features/onboarding/use-onboarding-checkout.test.ts b/apps/web/src/features/onboarding/use-onboarding-checkout.test.tsnew file mode 100644index 0000000000..f5bae24bc9--- /dev/null+++ b/apps/web/src/features/onboarding/use-onboarding-checkout.test.ts@@ -0,0 +1,43 @@+/**+ * @vitest-environment jsdom+ */++import { beforeEach, describe, expect, it, vi } from 'vitest';++const mocks = vi.hoisted(() => ({+ createCheckoutSessionV2: vi.fn(),+}));++vi.mock('@service-stripe/client', () => ({+ stripeServiceClient: {+ createCheckoutSessionV2: mocks.createCheckoutSessionV2,+ },+}));++import { createOnboardingCheckoutSession } from './use-onboarding-checkout';++beforeEach(() => {+ mocks.createCheckoutSessionV2.mockReset();+});++describe('createOnboardingCheckoutSession', () => {+ it('uses the supported v2 checkout endpoint and onboarding return URL', async () => {+ mocks.createCheckoutSessionV2.mockResolvedValue('https://checkout.test/1');++ await expect(createOnboardingCheckoutSession('premium')).resolves.toEqual({+ checkoutUrl: 'https://checkout.test/1',+ });+ expect(mocks.createCheckoutSessionV2).toHaveBeenCalledOnce();+ expect(mocks.createCheckoutSessionV2).toHaveBeenCalledWith({+ successUrl: `${window.location.origin}/app/welcome?subscriptionSuccess=true&type=premium`,+ });+ });++ it('rejects an empty checkout URL', async () => {+ mocks.createCheckoutSessionV2.mockResolvedValue('');++ await expect(createOnboardingCheckoutSession('premium')).rejects.toThrow(+ 'No checkout URL returned'+ );+ });+});diff --git a/apps/web/src/features/onboarding/use-onboarding-checkout.ts b/apps/web/src/features/onboarding/use-onboarding-checkout.tsindex e66715cfcf..bfc9464cf7 100644--- a/apps/web/src/features/onboarding/use-onboarding-checkout.ts+++ b/apps/web/src/features/onboarding/use-onboarding-checkout.ts@@ -18,6 +18,22 @@ interface OnboardingCheckoutResult {checkoutUrl: string;}+/** Creates a Stripe checkout session that returns to onboarding completion. */+export async function createOnboardingCheckoutSession(+ tier: PaidPlanTier+): Promise<OnboardingCheckoutResult> {+ const successUrl = `${window.location.origin}${ROUTER_BASE_CONCAT}welcome?subscriptionSuccess=true&type=${tier}`;+ const checkoutUrl = await stripeServiceClient.createCheckoutSessionV2({+ successUrl,+ });++ if (!checkoutUrl) {+ throw new Error('No checkout URL returned');+ }++ return { checkoutUrl };+}+// Pending team info is saved to localStorage before checkout redirect,// then retrieved and used to create the team after successful payment return.export function savePendingTeam(team: PendingTeamInfo): void {@@ -45,19 +61,8 @@ export function useOnboardingCheckoutMutation(callbacks?: {return useMutation(() => ({mutationFn: async (args: OnboardingCheckoutArgs- ): Promise<OnboardingCheckoutResult> => {- const successUrl = `${window.location.origin}${ROUTER_BASE_CONCAT}welcome?subscriptionSuccess=true&type=${args.tier}`;- const checkoutUrl = await stripeServiceClient.createCheckoutSession({- tier: args.tier,- successUrl,- });-- if (!checkoutUrl) {- throw new Error('No checkout URL returned');- }-- return { checkoutUrl };- },+ ): Promise<OnboardingCheckoutResult> =>+ await createOnboardingCheckoutSession(args.tier),onSuccess: callbacks?.onSuccess,onError: callbacks?.onError,}));diff --git a/apps/web/src/features/setup/flow/createFlowFinish.ts b/apps/web/src/features/setup/flow/createFlowFinish.tsindex 1eb5f9f674..b09963de10 100644--- a/apps/web/src/features/setup/flow/createFlowFinish.ts+++ b/apps/web/src/features/setup/flow/createFlowFinish.ts@@ -1,4 +1,4 @@-import { ROUTER_BASE_CONCAT } from '@app/constants/routerBase';+import { createOnboardingCheckoutSession } from '@app/features/onboarding/use-onboarding-checkout';import type { PaidPlanTier } from '@app/features/paywall/plans';import { useAnalytics } from '@app/lib/analytics/analytics-context';import { toast } from '@core/component/Toast/Toast';@@ -7,7 +7,6 @@ import { useCompleteTutorialMutation } from '@queries/auth/tutorial';import { useUserInfoQuery } from '@queries/auth/user-info';import { queryClient } from '@queries/client';import { useCompleteOnboardingMutation } from '@queries/onboarding';-import { stripeServiceClient } from '@service-stripe/client';import { useNavigate, useSearchParams } from '@solidjs/router';import { createEffect, createSignal } from 'solid-js';import { FLOW_NEXT_STORAGE_KEY, FLOW_STEP_STORAGE_KEY } from './shared';@@ -116,13 +115,7 @@ export function createFlowFinish(options?: {if (!(await completeFlow())) return;trackCompleted('premium', false);try {- // /welcome bounces authenticated users into the app.- const successUrl = `${window.location.origin}${ROUTER_BASE_CONCAT}welcome?subscriptionSuccess=true&type=${tier}`;- const checkoutUrl = await stripeServiceClient.createCheckoutSession({- tier,- successUrl,- });- if (!checkoutUrl) throw new Error('No checkout URL returned');+ const { checkoutUrl } = await createOnboardingCheckoutSession(tier);window.location.href = checkoutUrl;} catch {toast.failure(diff --git a/apps/web/src/lib/service-clients/service-auth/client.ts b/apps/web/src/lib/service-clients/service-auth/client.tsindex cb0e3125f8..3c25420712 100644--- a/apps/web/src/lib/service-clients/service-auth/client.ts+++ b/apps/web/src/lib/service-clients/service-auth/client.ts@@ -460,31 +460,6 @@ export const authServiceClient = {},// Stripe HTTP methods (replacing RPC calls)- async createCheckoutSession(args: {- successUrl: string;- cancelUrl: string;- discount?: string | null;- metadata?: {- gaClientId?: string | null;- fbp?: string | null;- fbc?: string | null;- };- tier?: string;- }) {- return (- await fetchWithAuth<{ url: string }>(`${authHost}/user/stripe/checkout`, {- method: 'POST',- body: JSON.stringify({- successUrl: args.successUrl,- cancelUrl: args.cancelUrl,- discount: args.discount ?? undefined,- metadata: args.metadata,- tier: args.tier ?? undefined,- }),- })- ).map((result) => result.url);- },-async createCheckoutSessionV2(args: {successUrl: string;cancelUrl: string;diff --git a/apps/web/src/lib/service-clients/service-stripe/client.ts b/apps/web/src/lib/service-clients/service-stripe/client.tsindex a8d23d5727..4c8b09233b 100644--- a/apps/web/src/lib/service-clients/service-stripe/client.ts+++ b/apps/web/src/lib/service-clients/service-stripe/client.ts@@ -33,45 +33,6 @@ function getGaClientId(): Promise<string | undefined> {}export const stripeServiceClient = {- /**- * Creates a checkout session- * @returns The URL of the checkout session- */- createCheckoutSession: async (- args: {- type?: string;- discount?: string;- tier?: string;- /** Override the default success URL. Useful for flows (e.g. onboarding) that want the user returned to a specific page. */- successUrl?: string;- } = {}- ) => {- const { type = '', discount, tier, successUrl } = args;- const gaClientId = await getGaClientId();- const { fbp, fbc } = getMetaIds();-- const result = await authServiceClient.createCheckoutSession({- successUrl:- successUrl ??- `${window.location.origin}/app/?subscriptionSuccess=true${type ? `&type=${type}` : ''}`,- cancelUrl: `${window.location.origin}/app?subscriptionCancel=true${tier ? `&tier=${tier}` : ''}`,- discount: discount ?? null,- metadata: {- gaClientId: gaClientId ?? null,- fbp: fbp ?? null,- fbc: fbc ?? null,- },- tier,- });-- if (!result.isOk()) {- throw new Error(- result.error?.[0]?.message ?? 'Failed to create checkout session'- );- }-- return result.value;- },/*** Creates a checkout session via the v2 endpoint. Unlike v1, this does not* accept a tier — the backend infers it from the new pricing model.