From 4f648f1e113cc4e0df99705dae4cb363e144fe3d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 7 Jul 2026 11:07:31 -0700 Subject: [PATCH] Simplify Connect onboarding to sign-in only - Remove device publishing flow from onboarding - Add per-account "Don't show this again" opt-out - Update mobile and web copy to T3 Connect --- apps/mobile/src/Stack.tsx | 4 +- apps/mobile/src/connection/platform.ts | 4 +- .../src/features/cloud/CloudAuthProvider.tsx | 12 +- .../cloud/CloudWaitlistEnrollment.tsx | 2 +- .../cloud/ConnectOnboardingRouteScreen.tsx | 485 ++---------------- .../src/features/cloud/connectOnboarding.ts | 58 +-- .../cloud/connectOnboardingNavigation.ts | 45 ++ .../features/cloud/connectOnboardingOptOut.ts | 21 + .../src/features/cloud/linkEnvironment.ts | 106 +--- .../connection/CloudEnvironmentRows.tsx | 6 +- .../connection/ConnectionEnvironmentRow.tsx | 2 +- .../connection/environmentSections.test.ts | 2 +- .../features/settings/SettingsRouteScreen.tsx | 4 +- apps/mobile/src/lib/storage.ts | 15 +- apps/web/src/cloud/connectOnboarding.ts | 18 +- .../cloud/ConnectOnboardingDialog.tsx | 121 +++-- apps/web/src/connection/platform.ts | 4 +- .../src/relay/discovery.test.ts | 49 ++ .../client-runtime/src/relay/discovery.ts | 16 +- .../src/relay/managedRelayState.ts | 8 +- 20 files changed, 300 insertions(+), 682 deletions(-) create mode 100644 apps/mobile/src/features/cloud/connectOnboardingNavigation.ts create mode 100644 apps/mobile/src/features/cloud/connectOnboardingOptOut.ts diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx index 4592400e92..7c12431911 100644 --- a/apps/mobile/src/Stack.tsx +++ b/apps/mobile/src/Stack.tsx @@ -18,7 +18,7 @@ import { ArchivedThreadsRouteScreen } from "./features/archive/ArchivedThreadsRo import { useAgentNotificationNavigation } from "./features/agent-awareness/notificationNavigation"; import { ClerkSettingsSheetDetentProvider } from "./features/cloud/ClerkSettingsSheetDetent"; import { ConnectOnboardingRouteScreen } from "./features/cloud/ConnectOnboardingRouteScreen"; -import { useConnectOnboardingNavigation } from "./features/cloud/connectOnboarding"; +import { useConnectOnboardingNavigation } from "./features/cloud/connectOnboardingNavigation"; import { ThreadFilesTreeScreen, ThreadFileScreen } from "./features/files/ThreadFilesRouteScreen"; import { AdaptiveWorkspaceLayout } from "./features/layout/AdaptiveWorkspaceLayout"; import { HardwareKeyboardCommandProvider } from "./features/keyboard/HardwareKeyboardCommandProvider"; @@ -423,7 +423,7 @@ export const RootStack = createNativeStackNavigator({ options: { gestureEnabled: true, presentation: "formSheet", - sheetAllowedDetents: [0.75, 0.95], + sheetAllowedDetents: [0.6, 0.95], sheetGrabberVisible: true, }, }), diff --git a/apps/mobile/src/connection/platform.ts b/apps/mobile/src/connection/platform.ts index 769632a8fc..fd3c153039 100644 --- a/apps/mobile/src/connection/platform.ts +++ b/apps/mobile/src/connection/platform.ts @@ -92,7 +92,7 @@ const capabilitiesLayer = Layer.succeedContext( if (session === null) { return yield* new ConnectionBlockedError({ reason: "authentication", - detail: "Sign in to T3 Cloud to connect this environment.", + detail: "Sign in to T3 Connect to connect this environment.", }); } const token = yield* session.readClerkToken().pipe( @@ -107,7 +107,7 @@ const capabilitiesLayer = Layer.succeedContext( if (token === null) { return yield* new ConnectionBlockedError({ reason: "authentication", - detail: "The T3 Cloud session is unavailable.", + detail: "The T3 Connect session is unavailable.", }); } return token; diff --git a/apps/mobile/src/features/cloud/CloudAuthProvider.tsx b/apps/mobile/src/features/cloud/CloudAuthProvider.tsx index 9d8e9d2576..85ab55491b 100644 --- a/apps/mobile/src/features/cloud/CloudAuthProvider.tsx +++ b/apps/mobile/src/features/cloud/CloudAuthProvider.tsx @@ -18,7 +18,7 @@ import { setAgentAwarenessRelayTokenProvider, unregisterAgentAwarenessDeviceForCurrentUser, } from "../agent-awareness/remoteRegistration"; -import { requestConnectOnboardingIfNeeded } from "./connectOnboarding"; +import { requestConnectOnboarding } from "./connectOnboarding"; import { resolveCloudPublicConfig, resolveRelayClerkTokenOptions } from "./publicConfig"; function resetManagedRelayTokenCache() { @@ -68,14 +68,12 @@ function CloudAuthBridge(props: { readonly children: ReactNode }) { const nextAccount = isSignedIn && userId ? userId : null; observedAccountRef.current = nextAccount; - // A sign-in that completed during this session (a cold start observes + // Every sign-in that completes during this session (a cold start observes // undefined → account and must not re-prompt) requests the T3 Connect - // onboarding sheet once per account. + // onboarding sheet — sign-out clears the connected environments, so each + // new session starts with no devices to reach. if (previousObservedAccount === null && nextAccount !== null) { - void (async () => { - const result = await settlePromise(() => requestConnectOnboardingIfNeeded(nextAccount)); - reportAtomCommandResult(result, { label: "connect onboarding request" }); - })(); + requestConnectOnboarding(nextAccount); } const queueAccountCleanup = ( diff --git a/apps/mobile/src/features/cloud/CloudWaitlistEnrollment.tsx b/apps/mobile/src/features/cloud/CloudWaitlistEnrollment.tsx index dbaf564e91..3bc51e397d 100644 --- a/apps/mobile/src/features/cloud/CloudWaitlistEnrollment.tsx +++ b/apps/mobile/src/features/cloud/CloudWaitlistEnrollment.tsx @@ -39,7 +39,7 @@ export function CloudWaitlistEnrollment(props: { readonly onSignIn: () => void } You are on the waitlist - We will email you when your T3 Cloud access is ready. + We will email you when your T3 Connect access is ready. diff --git a/apps/mobile/src/features/cloud/ConnectOnboardingRouteScreen.tsx b/apps/mobile/src/features/cloud/ConnectOnboardingRouteScreen.tsx index 9b132b4def..f7f4c26b35 100644 --- a/apps/mobile/src/features/cloud/ConnectOnboardingRouteScreen.tsx +++ b/apps/mobile/src/features/cloud/ConnectOnboardingRouteScreen.tsx @@ -1,67 +1,23 @@ import { useAuth } from "@clerk/expo"; import { useNavigation } from "@react-navigation/native"; -import * as Effect from "effect/Effect"; -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; -import { ActivityIndicator, Alert, Pressable, ScrollView, View } from "react-native"; +import { useCallback } from "react"; +import { Pressable, ScrollView, View } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; -import { - isAtomCommandInterrupted, - reportAtomCommandResult, - settleAsyncResult, - settlePromise, - squashAtomCommandFailure, -} from "@t3tools/client-runtime/state/runtime"; +import { reportAtomCommandResult, settlePromise } from "@t3tools/client-runtime/state/runtime"; import { AppText as Text } from "../../components/AppText"; -import type { SavedRemoteConnection } from "../../lib/connection"; -import { cn } from "../../lib/cn"; -import { runtime } from "../../lib/runtime"; -import { useThemeColor } from "../../lib/useThemeColor"; -import { - useRemoteConnections, - useSavedRemoteConnections, -} from "../../state/use-remote-environment-registry"; +import { useRemoteConnections } from "../../state/use-remote-environment-registry"; import { CloudEnvironmentRows } from "../connection/CloudEnvironmentRows"; import { splitEnvironmentSections } from "../connection/environmentSections"; -import { SettingsSection } from "../settings/components/SettingsSection"; -import { SettingsSwitchRow } from "../settings/components/SettingsSwitchRow"; -import { markConnectOnboardingCompleted } from "./connectOnboarding"; -import { - getEnvironmentConnectPublishState, - linkEnvironmentToCloud, - setEnvironmentPublishAgentActivity, -} from "./linkEnvironment"; -import { refreshManagedRelayEnvironments } from "./managedRelayState"; -import { hasCloudPublicConfig, resolveRelayClerkTokenOptions } from "./publicConfig"; - -type PublishTargetPhase = "checking" | "ready" | "published" | "unauthorized" | "error"; - -interface PublishTarget { - readonly connection: SavedRemoteConnection; - readonly phase: PublishTargetPhase; - readonly linked: boolean; - readonly managedTunnelActive: boolean; - readonly publishAgentActivity: boolean; - readonly error: string | null; -} - -function pendingPublishTarget(connection: SavedRemoteConnection): PublishTarget { - return { - connection, - phase: "checking", - linked: false, - managedTunnelActive: false, - publishAgentActivity: false, - error: null, - }; -} +import { optOutOfConnectOnboarding } from "./connectOnboardingOptOut"; +import { hasCloudPublicConfig } from "./publicConfig"; /** - * Post-sign-in onboarding sheet for T3 Connect. Offers to publish this - * device's locally paired environments (managed tunnel + agent activity, both - * defaulting on) when the paired session is authorized, then lists the - * account's T3 Connect environments so every device can be connected right - * away. Dismissing the sheet counts as completion — it never nags twice. + * Post-sign-in onboarding sheet for T3 Connect. Mobile never publishes + * environments itself — it consumes ones published elsewhere — so this simply + * surfaces the account's T3 Connect environments right after sign-in so every + * device can be connected in one go. It shows on every sign-in: sign-out + * clears the connected environments, so each new session starts from zero. */ export function ConnectOnboardingRouteScreen() { return hasCloudPublicConfig() ? : null; @@ -70,195 +26,26 @@ export function ConnectOnboardingRouteScreen() { function ConfiguredConnectOnboardingRouteScreen() { const navigation = useNavigation(); const insets = useSafeAreaInsets(); - const { getToken, isSignedIn, userId } = useAuth({ treatPendingAsSignedOut: false }); - const { isLoadingSavedConnection, savedConnectionsById } = useSavedRemoteConnections(); + const { isSignedIn, userId } = useAuth({ treatPendingAsSignedOut: false }); const { connectedEnvironments, onReconnectEnvironment } = useRemoteConnections(); const { connectedCloudEnvironments } = splitEnvironmentSections({ connectedEnvironments, cloudEnvironments: null, }); - // Dismissing the sheet (swipe, Skip, or Done) counts as completion. - const completionPersistedRef = useRef(false); - const persistCompletion = useCallback(() => { - if (completionPersistedRef.current || !userId) { - return; - } - completionPersistedRef.current = true; - void (async () => { - const result = await settlePromise(() => markConnectOnboardingCompleted(userId)); - reportAtomCommandResult(result, { label: "connect onboarding completion" }); - })(); - }, [userId]); - - useEffect( - () => navigation.addListener("beforeRemove", persistCompletion), - [navigation, persistCompletion], - ); - const handleDone = useCallback(() => { - persistCompletion(); navigation.goBack(); - }, [navigation, persistCompletion]); + }, [navigation]); - const bearerConnections = useMemo( - () => - Object.values(savedConnectionsById).filter((connection) => connection.bearerToken !== null), - [savedConnectionsById], - ); - - const [targets, setTargets] = useState | null>(null); - const [publishEnvironment, setPublishEnvironment] = useState(true); - const [publishAgentActivity, setPublishAgentActivity] = useState(true); - const [isApplying, setIsApplying] = useState(false); - - const loadPublishTargets = useCallback( - async (connections: ReadonlyArray) => { - if (connections.length === 0) { - setTargets([]); - return; - } - setTargets(connections.map(pendingPublishTarget)); - const result = await settleAsyncResult(() => - runtime.runPromiseExit( - Effect.forEach( - connections, - (connection) => - getEnvironmentConnectPublishState({ connection }).pipe( - Effect.match({ - onFailure: (error): PublishTarget => ({ - ...pendingPublishTarget(connection), - phase: "error", - error: error.message, - }), - onSuccess: (state): PublishTarget => ({ - connection, - phase: - state.canPublish === false - ? "unauthorized" - : state.linked && state.managedTunnelActive && state.publishAgentActivity - ? "published" - : "ready", - linked: state.linked, - managedTunnelActive: state.managedTunnelActive, - publishAgentActivity: state.publishAgentActivity, - error: null, - }), - }), - ), - { concurrency: "unbounded" }, - ), - ), - ); - if (result._tag === "Failure") { - if (isAtomCommandInterrupted(result)) { - return; - } - const error = squashAtomCommandFailure(result); - const message = - error instanceof Error ? error.message : "Could not check the environment link state."; - setTargets( - connections.map((connection) => ({ - ...pendingPublishTarget(connection), - phase: "error" as const, - error: message, - })), - ); - return; - } - setTargets(result.value); - }, - [], - ); - - // Check authorization + link state once the locally saved connections are - // ready. Loaded once per mount: reconnect churn in the registry must not - // flip the section back to "checking" mid-interaction. - const loadedRef = useRef(false); - useEffect(() => { - if (isLoadingSavedConnection || loadedRef.current) { - return; + const handleDontShowAgain = useCallback(() => { + if (userId) { + void (async () => { + const result = await settlePromise(() => optOutOfConnectOnboarding(userId)); + reportAtomCommandResult(result, { label: "connect onboarding opt-out" }); + })(); } - loadedRef.current = true; - void loadPublishTargets(bearerConnections); - }, [bearerConnections, isLoadingSavedConnection, loadPublishTargets]); - - const publishableTargets = useMemo( - () => (targets ?? []).filter((target) => target.phase === "ready"), - [targets], - ); - const targetConnections = useMemo( - () => (targets ?? []).map((target) => target.connection), - [targets], - ); - - const handlePublish = useCallback(async () => { - const applicable = publishableTargets; - if (applicable.length === 0 || (!publishEnvironment && !publishAgentActivity)) { - return; - } - setIsApplying(true); - const tokenResult = await settlePromise(() => getToken(resolveRelayClerkTokenOptions())); - const clerkToken = tokenResult._tag === "Success" ? tokenResult.value : null; - if (clerkToken === null) { - setIsApplying(false); - const error = tokenResult._tag === "Failure" ? squashAtomCommandFailure(tokenResult) : null; - Alert.alert( - "Publishing unavailable", - error instanceof Error ? error.message : "Sign in to publish environments over T3 Connect.", - ); - return; - } - - const failures: Array = []; - await Promise.all( - applicable.map(async (target) => { - // Onboarding only ever enables: it links when something is missing and - // never tears down an existing link or clears a preference. - const needsLink = publishEnvironment - ? !target.linked || !target.managedTunnelActive - : !target.linked && publishAgentActivity; - const applyEffect = Effect.gen(function* () { - if (needsLink) { - yield* linkEnvironmentToCloud({ - connection: target.connection, - clerkToken, - mode: publishEnvironment ? "managed" : "publish_only", - }); - } - if (publishAgentActivity && !target.publishAgentActivity) { - yield* setEnvironmentPublishAgentActivity({ - connection: target.connection, - publishAgentActivity: true, - }); - } - }); - const result = await settleAsyncResult(() => runtime.runPromiseExit(applyEffect)); - if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) { - const error = squashAtomCommandFailure(result); - failures.push( - `${target.connection.environmentLabel}: ${ - error instanceof Error ? error.message : "Publishing failed." - }`, - ); - } - }), - ); - - refreshManagedRelayEnvironments(); - await loadPublishTargets(targetConnections); - setIsApplying(false); - if (failures.length > 0) { - Alert.alert("Couldn't publish every environment", failures.join("\n\n")); - } - }, [ - getToken, - loadPublishTargets, - publishAgentActivity, - publishEnvironment, - publishableTargets, - targetConnections, - ]); + navigation.goBack(); + }, [navigation, userId]); return ( @@ -286,38 +73,15 @@ function ConfiguredConnectOnboardingRouteScreen() { - { - "Mesh your devices together — publish this device's environments and connect the rest, all in one place." - } + Environments published from your other devices are ready to connect here. {isSignedIn ? ( - <> - void handlePublish()} - onRetry={() => void loadPublishTargets(targetConnections)} - /> - - - - Connect your environments - - - Environments published from your other devices are ready to connect here. - - - - + ) : ( @@ -326,185 +90,26 @@ function ConfiguredConnectOnboardingRouteScreen() { )} - - Done - + + + Done + + {userId ? ( + + {"Don't show this again"} + + ) : null} + ); } - -function PublishSection(props: { - readonly targets: ReadonlyArray | null; - readonly publishEnvironment: boolean; - readonly publishAgentActivity: boolean; - readonly isApplying: boolean; - readonly onPublishEnvironmentChange: (enabled: boolean) => void; - readonly onPublishAgentActivityChange: (enabled: boolean) => void; - readonly onPublish: () => void; - readonly onRetry: () => void; -}) { - const iconColor = useThemeColor("--color-icon"); - const primaryForeground = useThemeColor("--color-primary-foreground"); - const targets = props.targets; - const isChecking = targets === null || targets.some((target) => target.phase === "checking"); - const publishableTargets = (targets ?? []).filter((target) => target.phase === "ready"); - const publishedTargets = (targets ?? []).filter((target) => target.phase === "published"); - const hasRetryableErrors = (targets ?? []).some((target) => target.phase === "error"); - const canPublish = - publishableTargets.length > 0 && - (props.publishEnvironment || props.publishAgentActivity) && - !props.isApplying; - - if (targets !== null && targets.length === 0) { - return ( - - - Publish this device - - - - { - "No locally paired environments on this device yet. Pair an environment first and it can be published to your other devices from Settings." - } - - - - ); - } - - if (isChecking) { - return ( - - - Publish this device - - - - - Checking which environments can publish. - - - - ); - } - - return ( - - - {publishableTargets.length > 0 ? ( - <> - - - - ) : publishedTargets.length > 0 ? ( - - - {"This device's environments already publish over T3 Connect."} - - - ) : ( - - - { - "This device's paired sessions aren't authorized to publish. Pair again with an administrative link to enable publishing." - } - - - )} - - - {publishableTargets.length > 0 ? ( - - Make the environments paired with this device available to your other devices, and send - agent activity for notifications and Live Activities. - - ) : null} - - {targets.map((target) => ( - - ))} - - {publishableTargets.length > 0 ? ( - - {props.isApplying ? : null} - - {props.isApplying - ? "Publishing..." - : `Publish ${publishableTargets.length === 1 ? "environment" : `${publishableTargets.length} environments`}`} - - - ) : null} - - {hasRetryableErrors ? ( - - Check again - - ) : null} - - ); -} - -function publishTargetStatusText(target: PublishTarget): string { - switch (target.phase) { - case "checking": - return "Checking..."; - case "published": - return "Already publishing"; - case "ready": - return target.linked ? "Partially published — ready to update" : "Ready to publish"; - case "unauthorized": - return "This device's session is not authorized to publish"; - case "error": - return target.error ?? "Could not check the environment"; - } -} - -function PublishTargetStatusRow(props: { readonly target: PublishTarget }) { - const isError = props.target.phase === "error"; - return ( - - - {props.target.connection.environmentLabel} - - - {publishTargetStatusText(props.target)} - - - ); -} diff --git a/apps/mobile/src/features/cloud/connectOnboarding.ts b/apps/mobile/src/features/cloud/connectOnboarding.ts index 3859a8fa3a..9d3944331a 100644 --- a/apps/mobile/src/features/cloud/connectOnboarding.ts +++ b/apps/mobile/src/features/cloud/connectOnboarding.ts @@ -1,68 +1,24 @@ -import { useAtomValue } from "@effect/atom-react"; -import { useNavigation } from "@react-navigation/native"; import { Atom } from "effect/unstable/reactivity"; -import { useEffect } from "react"; -import { loadPreferences, savePreferencesPatch } from "../../lib/storage"; import { appAtomRegistry } from "../../state/atom-registry"; // Signals RootStackLayout (inside the navigation tree) that an in-session -// sign-in just completed for an account that has not seen the T3 Connect -// onboarding sheet yet. Holds the account id so a sign-out between the request -// and the navigation cannot present the sheet for the wrong account. -const connectOnboardingRequestAtom = Atom.make(null).pipe( +// sign-in just completed. Holds the account id so a sign-out between the +// request and the navigation cannot present the sheet for the wrong account. +export const connectOnboardingRequestAtom = Atom.make(null).pipe( Atom.keepAlive, Atom.withLabel("mobile:connect-onboarding-request"), ); /** - * Requests the onboarding sheet for the given account unless it already - * completed (or skipped) onboarding on this device. + * Requests the onboarding sheet for the given account. Sign-out clears the + * connected environments, so onboarding runs on every in-session sign-in — + * each new session starts with no connected devices. */ -export async function requestConnectOnboardingIfNeeded(accountId: string): Promise { - const preferences = await loadPreferences(); - if (preferences.connectOnboardingCompletedAccounts?.includes(accountId)) { - return; - } +export function requestConnectOnboarding(accountId: string): void { appAtomRegistry.set(connectOnboardingRequestAtom, accountId); } export function clearConnectOnboardingRequest(): void { appAtomRegistry.set(connectOnboardingRequestAtom, null); } - -/** Persists that the account saw the sheet, so it never nags twice. */ -export async function markConnectOnboardingCompleted(accountId: string): Promise { - const preferences = await loadPreferences(); - const completed = preferences.connectOnboardingCompletedAccounts ?? []; - if (completed.includes(accountId)) { - return; - } - await savePreferencesPatch({ connectOnboardingCompletedAccounts: [...completed, accountId] }); -} - -// Sign-in happens inside the Settings sheet; give its detent/session-state -// transitions a beat to settle before presenting another formSheet on top. -const PRESENT_ONBOARDING_DELAY_MS = 600; - -/** - * Consumes the onboarding request inside the navigation tree (RootStackLayout) - * and presents the onboarding formSheet. - */ -export function useConnectOnboardingNavigation(): void { - const navigation = useNavigation(); - const requestedAccountId = useAtomValue(connectOnboardingRequestAtom); - - useEffect(() => { - if (requestedAccountId === null) { - return; - } - const timer = setTimeout(() => { - clearConnectOnboardingRequest(); - navigation.navigate("ConnectOnboarding"); - }, PRESENT_ONBOARDING_DELAY_MS); - return () => { - clearTimeout(timer); - }; - }, [navigation, requestedAccountId]); -} diff --git a/apps/mobile/src/features/cloud/connectOnboardingNavigation.ts b/apps/mobile/src/features/cloud/connectOnboardingNavigation.ts new file mode 100644 index 0000000000..97591f943e --- /dev/null +++ b/apps/mobile/src/features/cloud/connectOnboardingNavigation.ts @@ -0,0 +1,45 @@ +import { useAtomValue } from "@effect/atom-react"; +import { useNavigation } from "@react-navigation/native"; +import { useEffect } from "react"; + +import { clearConnectOnboardingRequest, connectOnboardingRequestAtom } from "./connectOnboarding"; +import { isConnectOnboardingOptedOut } from "./connectOnboardingOptOut"; + +// Sign-in happens inside the Settings sheet; give its detent/session-state +// transitions a beat to settle before presenting another formSheet on top. +const PRESENT_ONBOARDING_DELAY_MS = 600; + +/** + * Consumes the onboarding request inside the navigation tree (RootStackLayout) + * and presents the onboarding formSheet. Lives apart from connectOnboarding.ts + * so non-navigation consumers (CloudAuthProvider) do not pull + * @react-navigation into their module graph. + */ +export function useConnectOnboardingNavigation(): void { + const navigation = useNavigation(); + const requestedAccountId = useAtomValue(connectOnboardingRequestAtom); + + useEffect(() => { + if (requestedAccountId === null) { + return; + } + let cancelled = false; + const timer = setTimeout(() => { + void (async () => { + // A failed preference read prefers showing the sheet. + const optedOut = await isConnectOnboardingOptedOut(requestedAccountId).catch(() => false); + if (cancelled) { + return; + } + clearConnectOnboardingRequest(); + if (!optedOut) { + navigation.navigate("ConnectOnboarding"); + } + })(); + }, PRESENT_ONBOARDING_DELAY_MS); + return () => { + cancelled = true; + clearTimeout(timer); + }; + }, [navigation, requestedAccountId]); +} diff --git a/apps/mobile/src/features/cloud/connectOnboardingOptOut.ts b/apps/mobile/src/features/cloud/connectOnboardingOptOut.ts new file mode 100644 index 0000000000..0899509ea2 --- /dev/null +++ b/apps/mobile/src/features/cloud/connectOnboardingOptOut.ts @@ -0,0 +1,21 @@ +import { loadPreferences, savePreferencesPatch } from "../../lib/storage"; + +// Lives apart from connectOnboarding.ts so CloudAuthProvider (which imports +// the request signal) never pulls lib/storage — expo-secure-store — into its +// module graph; that breaks CloudAuthProvider.test.ts suite loading. + +/** Whether the account chose "Don't show this again". */ +export async function isConnectOnboardingOptedOut(accountId: string): Promise { + const preferences = await loadPreferences(); + return preferences.connectOnboardingOptOutAccounts?.includes(accountId) ?? false; +} + +/** Persists "Don't show this again" for the account. */ +export async function optOutOfConnectOnboarding(accountId: string): Promise { + const preferences = await loadPreferences(); + const optedOut = preferences.connectOnboardingOptOutAccounts ?? []; + if (optedOut.includes(accountId)) { + return; + } + await savePreferencesPatch({ connectOnboardingOptOutAccounts: [...optedOut, accountId] }); +} diff --git a/apps/mobile/src/features/cloud/linkEnvironment.ts b/apps/mobile/src/features/cloud/linkEnvironment.ts index cdfb59698e..a77ca62897 100644 --- a/apps/mobile/src/features/cloud/linkEnvironment.ts +++ b/apps/mobile/src/features/cloud/linkEnvironment.ts @@ -3,7 +3,6 @@ import * as Effect from "effect/Effect"; import * as Schema from "effect/Schema"; import { HttpClient } from "effect/unstable/http"; import { - AuthRelayWriteScope, EnvironmentCloudEndpointUnavailableError, EnvironmentHttpBadRequestError, EnvironmentHttpConflictError, @@ -77,13 +76,6 @@ const isEnvironmentCloudApiError = Schema.is( const MANAGED_ENDPOINT_PROVIDER_KIND = "cloudflare_tunnel" satisfies RelayManagedEndpointProviderKind; -// "publish_only" links the environment to the relay for agent-activity -// publishing alone: no managed tunnel is provisioned (mirrors the web client's -// CloudLinkMode). -export type CloudLinkMode = "managed" | "publish_only"; - -const PUBLISH_ONLY_PROVIDER_KIND = "manual" satisfies RelayManagedEndpointProviderKind; - function cloudEnvironmentLinkError(message: string) { return (cause: unknown) => { const environmentError = findEnvironmentCloudApiError(cause); @@ -267,7 +259,6 @@ function ensureConnectEndpointMatchesEnvironment(input: { export function linkEnvironmentToCloud(input: { readonly connection: SavedRemoteConnection; readonly clerkToken: string; - readonly mode?: CloudLinkMode; }): Effect.Effect< void, CloudEnvironmentLinkError, @@ -280,10 +271,6 @@ export function linkEnvironmentToCloud(input: { }); } const localBearerToken = input.connection.bearerToken; - const managedTunnelsEnabled = (input.mode ?? "managed") === "managed"; - const providerKind = managedTunnelsEnabled - ? MANAGED_ENDPOINT_PROVIDER_KIND - : PUBLISH_ONLY_PROVIDER_KIND; const relayUrl = yield* requireRelayUrl(); const relayClient = yield* ManagedRelay.ManagedRelayClient; const deviceId = yield* Effect.tryPromise({ @@ -301,7 +288,7 @@ export function linkEnvironmentToCloud(input: { payload: { notificationsEnabled: true, liveActivitiesEnabled, - managedTunnelsEnabled, + managedTunnelsEnabled: true, }, }) .pipe( @@ -319,7 +306,7 @@ export function linkEnvironmentToCloud(input: { endpoint: { httpBaseUrl: input.connection.httpBaseUrl, wsBaseUrl: input.connection.wsBaseUrl, - providerKind, + providerKind: MANAGED_ENDPOINT_PROVIDER_KIND, }, origin: endpointOrigin(input.connection.httpBaseUrl), }, @@ -333,7 +320,7 @@ export function linkEnvironmentToCloud(input: { proof, notificationsEnabled: true, liveActivitiesEnabled, - managedTunnelsEnabled, + managedTunnelsEnabled: true, }, }) .pipe( @@ -341,7 +328,7 @@ export function linkEnvironmentToCloud(input: { ); yield* ensureLinkedEnvironmentMatches({ expectedEnvironmentId: input.connection.environmentId, - expectedProviderKind: providerKind, + expectedProviderKind: MANAGED_ENDPOINT_PROVIDER_KIND, link, }); @@ -363,91 +350,6 @@ export function linkEnvironmentToCloud(input: { }); } -function requireBearerToken( - connection: SavedRemoteConnection, -): Effect.Effect { - return connection.bearerToken - ? Effect.succeed(connection.bearerToken) - : Effect.fail( - new CloudEnvironmentLinkError({ - message: "Only a locally paired bearer connection can publish over T3 Connect.", - }), - ); -} - -export interface EnvironmentConnectPublishState { - /** - * Whether the connection's session holds relay:write. `null` when the - * environment did not report session scopes (older servers) — callers should - * attempt publishing and surface the server's denial. - */ - readonly canPublish: boolean | null; - readonly linked: boolean; - readonly managedTunnelActive: boolean; - readonly publishAgentActivity: boolean; -} - -/** - * Reads the environment-side publish authorization (session scopes) and relay - * link state for a locally paired bearer connection. - */ -export function getEnvironmentConnectPublishState(input: { - readonly connection: SavedRemoteConnection; -}): Effect.Effect< - EnvironmentConnectPublishState, - CloudEnvironmentLinkError, - HttpClient.HttpClient -> { - return Effect.gen(function* () { - const localBearerToken = yield* requireBearerToken(input.connection); - const environmentClient = yield* makeEnvironmentHttpApiClient(input.connection.httpBaseUrl); - const headers = { authorization: `Bearer ${localBearerToken}` }; - const session = yield* environmentClient.auth - .session({ headers }) - .pipe(Effect.mapError(cloudEnvironmentLinkError("Could not read the environment session."))); - const linkState = yield* environmentClient.connect - .linkState({ headers }) - .pipe( - Effect.mapError(cloudEnvironmentLinkError("Could not read the environment link state.")), - ); - return { - canPublish: !session.authenticated - ? false - : session.scopes === undefined - ? null - : session.scopes.includes(AuthRelayWriteScope), - linked: linkState.linked, - managedTunnelActive: linkState.managedTunnelActive ?? linkState.linked, - publishAgentActivity: linkState.publishAgentActivity, - }; - }); -} - -/** - * Sets the environment-server-side "publish agent activity" preference. The - * link flow does not touch this secret, so clients opting into activity - * publishing must call it explicitly. - */ -export function setEnvironmentPublishAgentActivity(input: { - readonly connection: SavedRemoteConnection; - readonly publishAgentActivity: boolean; -}): Effect.Effect { - return Effect.gen(function* () { - const localBearerToken = yield* requireBearerToken(input.connection); - const environmentClient = yield* makeEnvironmentHttpApiClient(input.connection.httpBaseUrl); - yield* environmentClient.connect - .preferences({ - headers: { authorization: `Bearer ${localBearerToken}` }, - payload: { publishAgentActivity: input.publishAgentActivity }, - }) - .pipe( - Effect.mapError( - cloudEnvironmentLinkError("Could not update the environment publish preference."), - ), - ); - }); -} - export function listCloudEnvironments(input: { readonly clerkToken: string; }): Effect.Effect< diff --git a/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx b/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx index 27b99fabfd..2796d2e570 100644 --- a/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx +++ b/apps/mobile/src/features/connection/CloudEnvironmentRows.tsx @@ -25,7 +25,7 @@ import { ConnectionStatusDot } from "./ConnectionStatusDot"; import { type RelayEnvironmentView, useConnectionController } from "./useConnectionController"; /** - * "T3 Cloud" section: every environment published to the signed-in account, + * "T3 Connect" section: every environment published to the signed-in account, * with connect switches, availability status, refresh, and loading/error * states. Shared between the Settings environments screen and the T3 Connect * onboarding sheet. @@ -61,7 +61,7 @@ export function CloudEnvironmentRows(props: { return ( - T3 Cloud + T3 Connect - Could not load T3 Cloud environments + Could not load T3 Connect environments {controller.relayDiscovery.error} {controller.relayDiscovery.errorTraceId ? ( diff --git a/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx b/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx index 394bc18018..4b2da3e24c 100644 --- a/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx +++ b/apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx @@ -135,7 +135,7 @@ export function ConnectionEnvironmentRow(props: { > {props.environment.isRelayManaged ? ( - Managed by T3 Cloud. Tunnel details update automatically. + Managed by T3 Connect. Tunnel details update automatically. ) : ( <> diff --git a/apps/mobile/src/features/connection/environmentSections.test.ts b/apps/mobile/src/features/connection/environmentSections.test.ts index 497af4bfac..75f78738ad 100644 --- a/apps/mobile/src/features/connection/environmentSections.test.ts +++ b/apps/mobile/src/features/connection/environmentSections.test.ts @@ -35,7 +35,7 @@ function cloudEnvironment(environmentId: string): RelayClientEnvironmentRecord { } describe("mobile environment settings sections", () => { - it("keeps saved relay-managed connections under T3 Cloud", () => { + it("keeps saved relay-managed connections under T3 Connect", () => { const local = connectedEnvironment({ environmentId: "environment-local", isRelayManaged: false, diff --git a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx index 2b07b96b3c..a4a5499eee 100644 --- a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx @@ -240,8 +240,8 @@ function ConfiguredSettingsRouteScreen() { const promptSignIn = useCallback(() => { Alert.alert( - "Request T3 Cloud access", - "Live Activity updates require approved T3 Cloud access so relay can deliver updates to this device.", + "Request T3 Connect access", + "Live Activity updates require approved T3 Connect access so relay can deliver updates to this device.", [ { text: "Cancel", style: "cancel" }, { diff --git a/apps/mobile/src/lib/storage.ts b/apps/mobile/src/lib/storage.ts index 9d60b335e0..ed3191cfa2 100644 --- a/apps/mobile/src/lib/storage.ts +++ b/apps/mobile/src/lib/storage.ts @@ -69,8 +69,8 @@ export interface Preferences { /** Code/diff font size override; null/absent means derived from baseFontSize. */ readonly codeFontSize?: number | null; readonly codeWordBreak?: boolean; - /** Cloud account ids that already saw the T3 Connect onboarding sheet. */ - readonly connectOnboardingCompletedAccounts?: ReadonlyArray; + /** Cloud account ids that opted out of the T3 Connect onboarding sheet. */ + readonly connectOnboardingOptOutAccounts?: ReadonlyArray; } async function readStorageItem(key: MobileStorageKeyValue): Promise { @@ -169,7 +169,7 @@ export async function loadPreferences(): Promise { markdownFontSize?: number; codeFontSize?: number | null; codeWordBreak?: boolean; - connectOnboardingCompletedAccounts?: ReadonlyArray; + connectOnboardingOptOutAccounts?: ReadonlyArray; } = {}; if (typeof parsed.liveActivitiesEnabled === "boolean") { @@ -190,11 +190,10 @@ export async function loadPreferences(): Promise { if (typeof parsed.codeWordBreak === "boolean") { preferences.codeWordBreak = parsed.codeWordBreak; } - if (Array.isArray(parsed.connectOnboardingCompletedAccounts)) { - preferences.connectOnboardingCompletedAccounts = - parsed.connectOnboardingCompletedAccounts.filter( - (account): account is string => typeof account === "string", - ); + if (Array.isArray(parsed.connectOnboardingOptOutAccounts)) { + preferences.connectOnboardingOptOutAccounts = parsed.connectOnboardingOptOutAccounts.filter( + (account): account is string => typeof account === "string", + ); } return preferences; diff --git a/apps/web/src/cloud/connectOnboarding.ts b/apps/web/src/cloud/connectOnboarding.ts index 9ad08f929c..7d61e11c6c 100644 --- a/apps/web/src/cloud/connectOnboarding.ts +++ b/apps/web/src/cloud/connectOnboarding.ts @@ -1,18 +1,18 @@ import * as Schema from "effect/Schema"; /** - * Tracks which T3 Connect accounts have completed (or dismissed) the - * post-sign-in onboarding wizard, so it is shown at most once per account per - * browser. + * Accounts that opted out of the post-sign-in T3 Connect onboarding wizard + * ("Don't show this again"). The wizard otherwise shows on every sign-in, + * since sign-out clears the connected environments. */ -export const CONNECT_ONBOARDING_STORAGE_KEY = "t3code:connect-onboarding:v1"; +export const CONNECT_ONBOARDING_OPT_OUT_STORAGE_KEY = "t3code:connect-onboarding-opt-out:v1"; -export const ConnectOnboardingStateSchema = Schema.Struct({ - completedAccounts: Schema.Array(Schema.String), +export const ConnectOnboardingOptOutSchema = Schema.Struct({ + optOutAccounts: Schema.Array(Schema.String), }); -export type ConnectOnboardingState = typeof ConnectOnboardingStateSchema.Type; +export type ConnectOnboardingOptOutState = typeof ConnectOnboardingOptOutSchema.Type; -export const EMPTY_CONNECT_ONBOARDING_STATE: ConnectOnboardingState = { - completedAccounts: [], +export const EMPTY_CONNECT_ONBOARDING_OPT_OUT_STATE: ConnectOnboardingOptOutState = { + optOutAccounts: [], }; diff --git a/apps/web/src/components/cloud/ConnectOnboardingDialog.tsx b/apps/web/src/components/cloud/ConnectOnboardingDialog.tsx index 1568040a7a..9cca1d3c0b 100644 --- a/apps/web/src/components/cloud/ConnectOnboardingDialog.tsx +++ b/apps/web/src/components/cloud/ConnectOnboardingDialog.tsx @@ -4,9 +4,9 @@ import { CheckIcon } from "lucide-react"; import { useEffect, useMemo, useRef, useState } from "react"; import { - CONNECT_ONBOARDING_STORAGE_KEY, - ConnectOnboardingStateSchema, - EMPTY_CONNECT_ONBOARDING_STATE, + CONNECT_ONBOARDING_OPT_OUT_STORAGE_KEY, + ConnectOnboardingOptOutSchema, + EMPTY_CONNECT_ONBOARDING_OPT_OUT_STATE, } from "~/cloud/connectOnboarding"; import { hasCloudPublicConfig } from "~/cloud/publicConfig"; import { useCloudLinkController } from "~/cloud/useCloudLinkController"; @@ -16,6 +16,7 @@ import { cn } from "~/lib/utils"; import { useEnvironments, usePrimaryEnvironment } from "~/state/environments"; import { CloudEnvironmentConnectRows } from "./CloudEnvironmentConnectList"; import { Button } from "../ui/button"; +import { Checkbox } from "../ui/checkbox"; import { Dialog, DialogDescription, @@ -29,12 +30,13 @@ import { Switch } from "../ui/switch"; import { toastManager } from "../ui/toast"; /** - * Post-sign-in onboarding wizard for T3 Connect. Opens once per account (per - * browser) after the user is signed in: first prompts to publish this + * Post-sign-in onboarding wizard for T3 Connect. Opens on every in-session + * sign-in — sign-out removes the connected relay environments, so each new + * session starts with no devices to reach. It first prompts to publish this * environment (managed tunnel + agent activity, both defaulting on) when the * current session is authorized to manage the relay link, then lists the * account's T3 Connect environments so every device can be connected right - * away. Dismissing the dialog counts as completion — it never nags twice. + * away. A cold load with a restored session does not count as a sign-in. */ export function ConnectOnboardingDialog() { if (!hasCloudPublicConfig()) return null; @@ -46,10 +48,10 @@ type OnboardingStep = "publish" | "devices"; function ConfiguredConnectOnboardingDialog() { const { isLoaded, isSignedIn, userId } = useAuth(); - const [onboardingState, setOnboardingState] = useLocalStorage( - CONNECT_ONBOARDING_STORAGE_KEY, - EMPTY_CONNECT_ONBOARDING_STATE, - ConnectOnboardingStateSchema, + const [optOutState, setOptOutState] = useLocalStorage( + CONNECT_ONBOARDING_OPT_OUT_STORAGE_KEY, + EMPTY_CONNECT_ONBOARDING_OPT_OUT_STATE, + ConnectOnboardingOptOutSchema, ); const desktopBridge = window.desktopBridge; @@ -75,34 +77,54 @@ function ConfiguredConnectOnboardingDialog() { ? ["publish", "devices"] : ["devices"]; + const [requestedAccount, setRequestedAccount] = useState(null); const [openForAccount, setOpenForAccount] = useState(null); const [step, setStep] = useState("devices"); const [exposeEnvironment, setExposeEnvironment] = useState(true); const [publishAgentActivity, setPublishAgentActivity] = useState(true); + const [dontShowAgain, setDontShowAgain] = useState(false); const [isApplying, setIsApplying] = useState(false); const prefilledFromLinkStateRef = useRef(false); + const observedAccountRef = useRef(undefined); - const completedAccounts = onboardingState.completedAccounts; + const optOutAccounts = optOutState.optOutAccounts; + // Every sign-in that completes during this session requests the wizard. A + // cold load observes undefined → account and must not re-prompt — only a + // null → account transition is a sign-in. useEffect(() => { - if (!isLoaded || !isSignedIn || !userId) return; - if (openForAccount !== null) return; - if (completedAccounts.includes(userId)) return; + if (!isLoaded) return; + const previousAccount = observedAccountRef.current; + const nextAccount = isSignedIn && userId ? userId : null; + observedAccountRef.current = nextAccount; + if (previousAccount === null && nextAccount !== null) { + setRequestedAccount(nextAccount); + } + }, [isLoaded, isSignedIn, userId]); + + // Open once the session scopes resolve so the step set is stable. Accounts + // that chose "Don't show this again" are skipped. + useEffect(() => { + if (requestedAccount === null || openForAccount !== null) return; + if (optOutAccounts.includes(requestedAccount)) { + setRequestedAccount(null); + return; + } if (!sessionScopesKnown) return; + setRequestedAccount(null); prefilledFromLinkStateRef.current = false; setExposeEnvironment(true); setPublishAgentActivity(true); + setDontShowAgain(false); setStep(canManageRelay && controller.linkState.target !== null ? "publish" : "devices"); - setOpenForAccount(userId); + setOpenForAccount(requestedAccount); }, [ canManageRelay, - completedAccounts, controller.linkState.target, - isLoaded, - isSignedIn, openForAccount, + optOutAccounts, + requestedAccount, sessionScopesKnown, - userId, ]); // Signing out (or switching accounts) mid-wizard invalidates everything the @@ -111,7 +133,10 @@ function ConfiguredConnectOnboardingDialog() { if (openForAccount !== null && (!isSignedIn || userId !== openForAccount)) { setOpenForAccount(null); } - }, [isSignedIn, openForAccount, userId]); + if (requestedAccount !== null && (!isSignedIn || userId !== requestedAccount)) { + setRequestedAccount(null); + } + }, [isSignedIn, openForAccount, requestedAccount, userId]); // Toggles default on, but an environment that is already linked should show // its actual configuration instead of silently proposing to rewrite it. @@ -130,12 +155,13 @@ function ConfiguredConnectOnboardingDialog() { const complete = () => { const account = openForAccount; setOpenForAccount(null); - if (!account) return; - setOnboardingState((state) => - state.completedAccounts.includes(account) - ? state - : { completedAccounts: [...state.completedAccounts, account] }, - ); + if (account !== null && dontShowAgain) { + setOptOutState((state) => + state.optOutAccounts.includes(account) + ? state + : { optOutAccounts: [...state.optOutAccounts, account] }, + ); + } }; const applyPublishSelection = async () => { @@ -194,22 +220,33 @@ function ConfiguredConnectOnboardingDialog() { )} - - {step === "publish" ? ( - <> - - - - ) : ( - - )} + + +
+ {step === "publish" ? ( + <> + + + + ) : ( + + )} +
diff --git a/apps/web/src/connection/platform.ts b/apps/web/src/connection/platform.ts index f74465048f..56d25fa142 100644 --- a/apps/web/src/connection/platform.ts +++ b/apps/web/src/connection/platform.ts @@ -182,7 +182,7 @@ const capabilitiesLayer = Layer.effectContext( if (session === null) { return yield* new ConnectionBlockedError({ reason: "authentication", - detail: "Sign in to T3 Cloud to connect this environment.", + detail: "Sign in to T3 Connect to connect this environment.", }); } const token = yield* session.readClerkToken().pipe( @@ -197,7 +197,7 @@ const capabilitiesLayer = Layer.effectContext( if (token === null) { return yield* new ConnectionBlockedError({ reason: "authentication", - detail: "The T3 Cloud session is unavailable.", + detail: "The T3 Connect session is unavailable.", }); } return token; diff --git a/packages/client-runtime/src/relay/discovery.test.ts b/packages/client-runtime/src/relay/discovery.test.ts index 66c27b8678..8cb963000b 100644 --- a/packages/client-runtime/src/relay/discovery.test.ts +++ b/packages/client-runtime/src/relay/discovery.test.ts @@ -342,6 +342,55 @@ describe("RelayEnvironmentDiscovery", () => { }), ); + it.effect("refreshes proactively when credentials change before any manual refresh", () => + Effect.gen(function* () { + const harness = yield* makeHarness(); + yield* Effect.gen(function* () { + const discovery = yield* RelayEnvironmentDiscovery.RelayEnvironmentDiscovery; + const requests = yield* Ref.get(harness.statusRequests); + for (const environment of environments) { + yield* Deferred.succeed( + requests.get(environment.environmentId)!, + status(environment, "online"), + ); + } + + // Let the scoped wakeup subscription start before emitting, mirroring + // a real sign-in which always happens long after service start. + yield* Effect.yieldNow; + + // Sign-in activates the session and emits credentials-changed; the + // list must populate without any screen having asked for a refresh. + yield* harness.wake("credentials-changed"); + const populated = yield* SubscriptionRef.changes(discovery.state).pipe( + Stream.filter( + (state) => state.environments.size === environments.length && !state.refreshing, + ), + Stream.runHead, + Effect.map(Option.getOrThrow), + ); + expect(Option.isNone(populated.error)).toBe(true); + expect(yield* Ref.get(harness.listCalls)).toBe(1); + }).pipe(Effect.provide(harness.layer), Effect.scoped); + }), + ); + + it.effect("settles to a clean empty state when refreshed while signed out", () => + Effect.gen(function* () { + const harness = yield* makeHarness(); + yield* Effect.gen(function* () { + const discovery = yield* RelayEnvironmentDiscovery.RelayEnvironmentDiscovery; + yield* Ref.set(harness.clerkToken, null); + yield* discovery.refresh; + + const state = yield* SubscriptionRef.get(discovery.state); + expect(state.environments.size).toBe(0); + expect(state.refreshing).toBe(false); + expect(Option.isNone(state.error)).toBe(true); + }).pipe(Effect.provide(harness.layer)); + }), + ); + it.effect("does not republish stale rows after sign-out invalidates an in-flight refresh", () => Effect.gen(function* () { const harness = yield* makeHarness(); diff --git a/packages/client-runtime/src/relay/discovery.ts b/packages/client-runtime/src/relay/discovery.ts index 8cbadea1ca..9ef99e2fce 100644 --- a/packages/client-runtime/src/relay/discovery.ts +++ b/packages/client-runtime/src/relay/discovery.ts @@ -279,10 +279,15 @@ export const make = Effect.fn("RelayEnvironmentDiscovery.make")(function* () { if ((yield* Ref.get(accountGeneration)) !== generation) { return; } + // Signed out is the idle state, not a failure: the proactive + // refresh on credentials-changed also runs on sign-out and must + // settle back to a clean empty list. + const signedOut = + error._tag === "ConnectionBlockedError" && error.reason === "authentication"; yield* SubscriptionRef.update(state, (current) => ({ ...current, refreshing: false, - error: Option.some(error), + error: signedOut ? Option.none() : Option.some(error), })); }), ), @@ -311,11 +316,12 @@ export const make = Effect.fn("RelayEnvironmentDiscovery.make")(function* () { yield* Ref.update(accountGeneration, (current) => current + 1); yield* Ref.set(activeAccountId, Option.none()); yield* Ref.set(offlineReportFingerprints, new Map()); - const shouldRefresh = yield* Ref.get(hasRefreshed); yield* SubscriptionRef.set(state, EMPTY_RELAY_ENVIRONMENT_DISCOVERY_STATE); - if (shouldRefresh) { - yield* refresh.pipe(Effect.forkScoped); - } + // Refresh proactively — this wakeup fires when a session activates + // (sign-in or cold start), and the list should be populated before + // any screen asks for it. A signed-out refresh settles back to the + // clean empty state. + yield* refresh.pipe(Effect.forkScoped); }) : Effect.void, ), diff --git a/packages/client-runtime/src/relay/managedRelayState.ts b/packages/client-runtime/src/relay/managedRelayState.ts index ec6a0710dd..1d12c90aae 100644 --- a/packages/client-runtime/src/relay/managedRelayState.ts +++ b/packages/client-runtime/src/relay/managedRelayState.ts @@ -123,7 +123,7 @@ export function createManagedRelaySession(input: ManagedRelaySessionInput): Mana try: () => readCachedClerkToken(nowMillis), catch: (cause) => new ManagedRelaySessionError({ - message: "Could not obtain the T3 Cloud session token.", + message: "Could not obtain the T3 Connect session token.", cause, }), }); @@ -181,7 +181,7 @@ function readSessionClerkToken( ? Effect.succeed(token) : Effect.fail( new ManagedRelaySessionError({ - message: "The T3 Cloud session token is unavailable.", + message: "The T3 Connect session token is unavailable.", }), ), ), @@ -226,7 +226,7 @@ function requireClerkToken( if (!session || session.accountId !== accountId) { return Effect.fail( new ManagedRelaySessionError({ - message: "Sign in to T3 Cloud before loading relay data.", + message: "Sign in to T3 Connect before loading relay data.", }), ); } @@ -296,7 +296,7 @@ export function readManagedRelaySnapshotState( let errorTraceId: string | null = null; if (result._tag === "Failure") { const cause = Cause.squash(result.cause); - error = cause instanceof Error ? cause.message : "Could not load T3 Cloud data."; + error = cause instanceof Error ? cause.message : "Could not load T3 Connect data."; errorTraceId = findErrorTraceId(cause); } return {