-
Notifications
You must be signed in to change notification settings - Fork 5.5k
feat(connect): deregister account environments from any client #4844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
juliusmarminge
merged 8 commits into
pingdotgg:main
from
StiensWout:feat/deregister-t3-connect-hosts
Aug 12, 2026
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e66ad13
feat(connect): deregister account environments from any client
StiensWout bd3f6a5
fix(connect): keep refreshed account environments visible
StiensWout 2521427
fix(mobile): use the Clerk Expo package
StiensWout 85a4d07
fix(connect): show account deregistration confirmation
StiensWout bb7ab75
fix(mobile): exit unavailable T3 Connect route
StiensWout 5b7acc5
refactor(web): align Clerk profile pages
juliusmarminge 072722e
refactor(mobile): make T3 Connect environments read-only
juliusmarminge c3b2844
refactor(mobile): remove T3 Connect account screen
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
232 changes: 232 additions & 0 deletions
232
apps/mobile/src/features/settings/SettingsT3ConnectRouteScreen.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| import { findErrorTraceId } from "@t3tools/client-runtime/errors"; | ||
| import { | ||
| isAtomCommandInterrupted, | ||
| squashAtomCommandFailure, | ||
| } from "@t3tools/client-runtime/state/runtime"; | ||
| import type { EnvironmentId } from "@t3tools/contracts"; | ||
| import type { RelayClientEnvironmentRecord } from "@t3tools/contracts/relay"; | ||
| import { useAuth } from "@clerk/clerk-expo"; | ||
| import { useNavigation } from "@react-navigation/native"; | ||
| import { useRef, useState } from "react"; | ||
| import { Alert, Platform, Pressable, RefreshControl, ScrollView, View } from "react-native"; | ||
| import { useSafeAreaInsets } from "react-native-safe-area-context"; | ||
|
|
||
| import { AndroidScreenHeader } from "../../components/AndroidScreenHeader"; | ||
| import { AppText as Text } from "../../components/AppText"; | ||
| import { showConfirmDialog } from "../../components/ConfirmDialogHost"; | ||
| import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic"; | ||
| import { NativeStackScreenOptions } from "../../native/StackHeader"; | ||
| import { | ||
| deregisterManagedRelayEnvironmentCommand, | ||
| useManagedRelayEnvironments, | ||
| } from "../cloud/managedRelayState"; | ||
| import { useAtomCommand } from "../../state/use-atom-command"; | ||
|
|
||
| const linkedAtFormatter = new Intl.DateTimeFormat(undefined, { dateStyle: "medium" }); | ||
|
|
||
| function linkedAtLabel(value: string): string { | ||
| const linkedAt = new Date(value); | ||
| return Number.isNaN(linkedAt.getTime()) | ||
| ? "Link date unavailable" | ||
| : `Linked ${linkedAtFormatter.format(linkedAt)}`; | ||
| } | ||
|
|
||
| function endpointLabel(environment: RelayClientEnvironmentRecord): string { | ||
| return environment.endpoint.providerKind === "cloudflare_tunnel" | ||
| ? "Managed tunnel" | ||
| : "Activity publishing only"; | ||
| } | ||
|
|
||
| export function SettingsT3ConnectRouteScreen() { | ||
| const { isLoaded: isAuthLoaded, isSignedIn } = useAuth({ treatPendingAsSignedOut: false }); | ||
| const navigation = useNavigation(); | ||
| const insets = useSafeAreaInsets(); | ||
| const environmentsState = useManagedRelayEnvironments(); | ||
| const deregisterEnvironment = useAtomCommand(deregisterManagedRelayEnvironmentCommand, { | ||
| reportFailure: false, | ||
| }); | ||
| const mutationPendingRef = useRef(false); | ||
| const [deregisteringEnvironmentId, setDeregisteringEnvironmentId] = | ||
| useState<EnvironmentId | null>(null); | ||
| const [removedEnvironments, setRemovedEnvironments] = useState<{ | ||
| readonly accountId: string | null; | ||
| readonly linkedAtById: ReadonlyMap<EnvironmentId, string>; | ||
| }>({ accountId: null, linkedAtById: new Map() }); | ||
|
|
||
| const deregister = async (environment: RelayClientEnvironmentRecord) => { | ||
| const accountId = environmentsState.accountId; | ||
| if (!accountId || mutationPendingRef.current) return; | ||
|
|
||
| mutationPendingRef.current = true; | ||
| setDeregisteringEnvironmentId(environment.environmentId); | ||
| const result = await deregisterEnvironment({ | ||
| accountId, | ||
| environmentId: environment.environmentId, | ||
| }); | ||
| mutationPendingRef.current = false; | ||
| setDeregisteringEnvironmentId(null); | ||
|
|
||
| if (result._tag === "Success") { | ||
| setRemovedEnvironments((current) => { | ||
| const linkedAtById = new Map(current.accountId === accountId ? current.linkedAtById : []); | ||
| linkedAtById.set(environment.environmentId, environment.linkedAt); | ||
| return { accountId, linkedAtById }; | ||
| }); | ||
| environmentsState.refresh(); | ||
| Alert.alert( | ||
| "Server deregistered", | ||
| `${environment.label} no longer has T3 Connect access. A host space is now available.`, | ||
| ); | ||
| return; | ||
| } | ||
| if (isAtomCommandInterrupted(result)) return; | ||
|
|
||
| const cause = squashAtomCommandFailure(result); | ||
| const message = cause instanceof Error ? cause.message : "Could not deregister the server."; | ||
| const traceId = findErrorTraceId(cause); | ||
| console.error("[t3-connect] Could not deregister environment", { | ||
| environmentId: environment.environmentId, | ||
| message, | ||
| traceId, | ||
| cause, | ||
| }); | ||
| Alert.alert( | ||
| "Could not deregister server", | ||
| message, | ||
| traceId | ||
| ? [ | ||
| { text: "Dismiss", style: "cancel" }, | ||
| { | ||
| text: "Copy trace ID", | ||
| onPress: () => copyTextWithHaptic(traceId, { target: "trace ID" }), | ||
| }, | ||
| ] | ||
| : undefined, | ||
| ); | ||
| }; | ||
|
|
||
| const confirmDeregister = (environment: RelayClientEnvironmentRecord) => { | ||
| const title = `Deregister “${environment.label}”?`; | ||
| const message = | ||
| "This revokes this server’s T3 Connect access, removes any managed tunnel, and frees a host space. Local connections on your devices are not changed."; | ||
| const onConfirm = () => void deregister(environment); | ||
| if (Platform.OS === "ios") { | ||
| Alert.alert(title, message, [ | ||
| { text: "Cancel", style: "cancel" }, | ||
| { text: "Deregister", style: "destructive", onPress: onConfirm }, | ||
| ]); | ||
| return; | ||
| } | ||
| showConfirmDialog({ | ||
| title, | ||
| message, | ||
| confirmText: "Deregister", | ||
| destructive: true, | ||
| onConfirm, | ||
| }); | ||
| }; | ||
|
|
||
| const removedEnvironmentLinkedAt = | ||
| removedEnvironments.accountId === environmentsState.accountId | ||
| ? removedEnvironments.linkedAtById | ||
| : new Map<EnvironmentId, string>(); | ||
| const environments = (environmentsState.data ?? []).filter( | ||
| (environment) => | ||
| removedEnvironmentLinkedAt.get(environment.environmentId) !== environment.linkedAt, | ||
| ); | ||
| const isSignedOut = isAuthLoaded && !isSignedIn; | ||
| const isAccountLoading = !isSignedOut && environmentsState.accountId === null; | ||
| const isInitialLoad = | ||
| environmentsState.accountId !== null && | ||
| environmentsState.data === null && | ||
| !environmentsState.error; | ||
|
|
||
| return ( | ||
| <View collapsable={false} className="flex-1 bg-sheet"> | ||
| {Platform.OS === "android" ? ( | ||
| <> | ||
| <NativeStackScreenOptions options={{ headerShown: false }} /> | ||
| <AndroidScreenHeader title="T3 Connect" onBack={() => navigation.goBack()} /> | ||
| </> | ||
| ) : null} | ||
| <ScrollView | ||
| contentInsetAdjustmentBehavior="automatic" | ||
| showsVerticalScrollIndicator={false} | ||
| className="flex-1" | ||
| contentContainerClassName="px-5 pt-4" | ||
| contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }} | ||
| refreshControl={ | ||
| environmentsState.accountId ? ( | ||
| <RefreshControl | ||
| refreshing={environmentsState.isPending} | ||
| onRefresh={environmentsState.refresh} | ||
| /> | ||
| ) : undefined | ||
| } | ||
| > | ||
| <View className="gap-1 pb-5"> | ||
| <Text className="text-lg font-t3-bold text-foreground">Account environments</Text> | ||
| <Text className="text-sm leading-normal text-foreground-muted"> | ||
| Servers registered to your account. Connections on this device stay in Environments. | ||
| </Text> | ||
| </View> | ||
|
|
||
| {environmentsState.error ? ( | ||
|
StiensWout marked this conversation as resolved.
Outdated
|
||
| <View className="border-y border-danger-border py-4"> | ||
| <Text className="text-base font-t3-medium text-danger-foreground"> | ||
| Could not load T3 Connect environments | ||
| </Text> | ||
| <Text className="mt-1 text-sm text-foreground-muted">{environmentsState.error}</Text> | ||
| </View> | ||
| ) : null} | ||
|
|
||
| {isSignedOut ? ( | ||
| <Text className="border-y border-border py-6 text-sm text-foreground-muted"> | ||
| Sign in to T3 Connect to manage account environments. | ||
| </Text> | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
| ) : isAccountLoading || isInitialLoad ? ( | ||
| <Text className="border-y border-border py-6 text-sm text-foreground-muted"> | ||
| Loading environments… | ||
| </Text> | ||
| ) : environments.length > 0 ? ( | ||
| <View> | ||
| {environments.map((environment, index) => ( | ||
| <View | ||
| key={environment.environmentId} | ||
| className={index === 0 ? "py-4" : "border-t border-border py-4"} | ||
| > | ||
| <View className="flex-row items-center gap-4"> | ||
| <View className="min-w-0 flex-1"> | ||
| <Text className="text-base font-t3-medium text-foreground" numberOfLines={1}> | ||
| {environment.label} | ||
| </Text> | ||
| <Text className="mt-1 text-sm text-foreground-muted" numberOfLines={1}> | ||
| {linkedAtLabel(environment.linkedAt)} · {endpointLabel(environment)} | ||
| </Text> | ||
| </View> | ||
| <Pressable | ||
| accessibilityLabel={`Deregister ${environment.label}`} | ||
| accessibilityRole="button" | ||
| disabled={deregisteringEnvironmentId !== null} | ||
| className="px-2 py-2 disabled:opacity-40" | ||
| onPress={() => confirmDeregister(environment)} | ||
| > | ||
| <Text className="font-t3-medium text-danger-foreground"> | ||
| {deregisteringEnvironmentId === environment.environmentId | ||
| ? "Deregistering…" | ||
| : "Deregister"} | ||
| </Text> | ||
| </Pressable> | ||
| </View> | ||
| </View> | ||
| ))} | ||
| </View> | ||
| ) : environmentsState.error ? null : ( | ||
| <Text className="border-y border-border py-6 text-sm text-foreground-muted"> | ||
| No environments are registered to this T3 Connect account. | ||
| </Text> | ||
| )} | ||
| </ScrollView> | ||
| </View> | ||
| ); | ||
| } | ||
1 change: 1 addition & 0 deletions
1
apps/mobile/src/features/settings/components/settings-sheet-targets.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.