@devries-cameron20 / t3code Mirror · read-only / commits / 263eef215d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 20:45 UTC

refactor(web): authorized clients and endpoint rows live in their own file (#22684)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 01:39 UTC 263eef215de4df504235609e1daaacd637fa42c7
3 files changed +1002 -962
apps/web/src/components/settings/AuthorizedClientsSettings.tsx new
+992
@@ -0,0 +1,992 @@
1 +import { AUTH_SCOPE_OPTIONS as PAIRING_SCOPE_OPTIONS } from "@t3tools/shared/authScopeOptions";
2 +import { PlusIcon, QrCodeIcon } from "lucide-react";
3 +import { type ReactNode, memo, useId, useState } from "react";
4 +import {
5 + AuthAccessWriteScope,
6 + AuthDiagnosticsReadScope,
7 + AuthOrchestrationReadScope,
8 + AuthFilesystemReadScope,
9 + AuthStandardClientScopes,
10 + AuthTerminalReadScope,
11 + type AuthEnvironmentScope,
12 + type AuthGrantScope,
13 + type AuthPairingCredentialResult,
14 + type AdvertisedEndpoint,
15 +} from "@t3tools/contracts";
16 +import { settlePromise } from "@t3tools/client-runtime/state/runtime";
17 +import * as Cause from "effect/Cause";
18 +
19 +import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
20 +import { cn } from "../../lib/utils";
21 +import { formatElapsedDurationLabel, formatExpiresInLabel } from "../../timestampFormat";
22 +import { resolveDesktopPairingUrl, resolveHostedPairingUrl } from "./pairingUrls";
23 +import {
24 + canRevokeOtherClients,
25 + isQrShareableEndpoint,
26 + selectQrEndpointOption,
27 + togglePairingScopeSelection,
28 +} from "./ConnectionsSettings.logic";
29 +import { useRelativeTimeTick } from "./settingsLayout";
30 +import { Input } from "../ui/input";
31 +import { Checkbox } from "../ui/checkbox";
32 +import {
33 + Dialog,
34 + DialogFooter,
35 + DialogDescription,
36 + DialogHeader,
37 + DialogPanel,
38 + DialogPopup,
39 + DialogTitle,
40 + DialogTrigger,
41 +} from "../ui/dialog";
42 +import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
43 +import { QRCodeSvg } from "../ui/qr-code";
44 +import { stackedThreadToast, toastManager } from "../ui/toast";
45 +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
46 +import { Button } from "../ui/button";
47 +import { Textarea } from "../ui/textarea";
48 +import {
49 + createServerPairingCredential,
50 + isLoopbackHostname,
51 + type ServerClientSessionRecord,
52 + type ServerPairingLinkRecord,
53 +} from "~/environments/primary";
54 +import { readEnvironmentScope } from "~/state/session";
55 +import { usePrimaryEnvironmentId } from "~/state/environments";
56 +import { ConnectionStatusDot } from "../ConnectionStatusDot";
57 +import { ITEM_ROW_CLASSNAME, ITEM_ROW_INNER_CLASSNAME } from "./itemRows";
58 +import {
59 + formatAccessTimestamp,
60 + selectPairingEndpoint,
61 + isTailscaleHttpsEndpoint,
62 + endpointDefaultPreferenceKey,
63 + resolveAdvertisedEndpointPairingUrl,
64 + resolveCurrentOriginPairingUrl,
65 + isHostedAppPairingUrl,
66 + endpointShareHint,
67 +} from "./ConnectionsSettings.logic";
68 +
69 +function AccessScopeSummary({
70 + scopes,
71 + label,
72 +}: {
73 + readonly scopes: ReadonlyArray<AuthEnvironmentScope>;
74 + readonly label: string;
75 +}) {
76 + const scopeCountLabel = `${scopes.length} ${scopes.length === 1 ? "scope" : "scopes"}`;
77 +
78 + return (
79 + <Popover>
80 + <PopoverTrigger
81 + openOnHover
82 + delay={250}
83 + closeDelay={100}
84 + render={
85 + <button
86 + type="button"
87 + aria-label={`${label}: show ${scopeCountLabel}`}
88 + className="cursor-help underline decoration-border underline-offset-2 outline-hidden hover:text-foreground focus-visible:text-foreground"
89 + />
90 + }
91 + >
92 + {scopeCountLabel}
93 + </PopoverTrigger>
94 + <PopoverPopup
95 + side="top"
96 + align="start"
97 + tooltipStyle
98 + className="w-max max-w-80 whitespace-normal"
99 + >
100 + <p className="mb-1 font-medium">Granted scopes</p>
101 + <div className="flex flex-col gap-0.5">
102 + {scopes.map((scope) => (
103 + <code key={scope} className="font-mono text-foreground/85">
104 + {scope}
105 + </code>
106 + ))}
107 + </div>
108 + </PopoverPopup>
109 + </Popover>
110 + );
111 +}
112 +
113 +const ENDPOINT_ROW_CLASSNAME = "first:rounded-t-xl last:rounded-b-xl px-3 py-2.5 sm:px-4";
114 +
115 +export type AccessSectionPresentation = "current" | "endpoint-rail";
116 +
117 +export function accessRowClassName(_presentation: AccessSectionPresentation) {
118 + return ITEM_ROW_CLASSNAME;
119 +}
120 +
121 +function endpointRowClassName(presentation: AccessSectionPresentation, isAvailable: boolean) {
122 + if (presentation === "endpoint-rail") {
123 + return cn(
124 + "relative first:rounded-t-xl last:rounded-b-xl px-3 py-3 sm:px-4",
125 + !isAvailable && "bg-muted/15",
126 + );
127 + }
128 +
129 + return cn(ENDPOINT_ROW_CLASSNAME, !isAvailable && "bg-muted/24");
130 +}
131 +
132 +type PairingLinkListRowProps = {
133 + pairingLink: ServerPairingLinkRecord;
134 + credential: string | undefined;
135 + endpointUrl: string | null | undefined;
136 + endpoints: ReadonlyArray<AdvertisedEndpoint>;
137 + defaultEndpointKey: string | null;
138 + presentation?: AccessSectionPresentation;
139 + revokingPairingLinkId: string | null;
140 + onRevoke: (id: string) => void;
141 + canRevoke: boolean;
142 +};
143 +
144 +const PairingLinkListRow = memo(function PairingLinkListRow({
145 + pairingLink,
146 + credential,
147 + endpointUrl,
148 + endpoints,
149 + defaultEndpointKey,
150 + presentation = "current",
151 + revokingPairingLinkId,
152 + onRevoke,
153 + canRevoke,
154 +}: PairingLinkListRowProps) {
155 + const nowMs = useRelativeTimeTick(1_000);
156 + const expiresAtMs = new Date(pairingLink.expiresAt).getTime();
157 + const [isRevealDialogOpen, setIsRevealDialogOpen] = useState(false);
158 + const [isQrPanelOpen, setIsQrPanelOpen] = useState(false);
159 + const [qrEndpointId, setQrEndpointId] = useState<string | null>(null);
160 + const qrPanelId = useId();
161 +
162 + const currentOriginPairingUrl = credential ? resolveCurrentOriginPairingUrl(credential) : null;
163 + const hostedPairingUrl =
164 + credential && endpointUrl != null && endpointUrl !== ""
165 + ? resolveHostedPairingUrl(endpointUrl, credential)
166 + : null;
167 + const endpointPairingUrl = (() => {
168 + const endpoint = selectPairingEndpoint(endpoints, defaultEndpointKey);
169 + return endpoint && credential
170 + ? resolveAdvertisedEndpointPairingUrl(endpoint, credential)
171 + : null;
172 + })();
173 + const endpointCopyOptions = (() => {
174 + const options: Array<{
175 + readonly id: string;
176 + readonly preferenceKey: string;
177 + readonly label: string;
178 + readonly url: string;
179 + readonly detail: string;
180 + readonly qrShareable: boolean;
181 + }> = [];
182 + if (!credential) return options;
183 + for (const endpoint of endpoints) {
184 + if (endpoint.status === "unavailable") {
185 + continue;
186 + }
187 + const url = resolveAdvertisedEndpointPairingUrl(endpoint, credential);
188 + options.push({
189 + id: endpoint.id,
190 + preferenceKey: endpointDefaultPreferenceKey(endpoint),
191 + label: endpoint.label,
192 + url,
193 + detail: endpointShareHint(endpoint, url),
194 + qrShareable: isQrShareableEndpoint(endpoint),
195 + });
196 + }
197 + return options;
198 + })();
199 + const shareablePairingUrl =
200 + endpointPairingUrl ??
201 + (credential && endpointUrl != null && endpointUrl !== ""
202 + ? (hostedPairingUrl ?? resolveDesktopPairingUrl(endpointUrl, credential))
203 + : isLoopbackHostname(window.location.hostname)
204 + ? null
205 + : currentOriginPairingUrl);
206 + const [failedCopyValue, setFailedCopyValue] = useState<string | null>(null);
207 + const revealValue = failedCopyValue ?? shareablePairingUrl ?? credential ?? "";
208 + const isRevealValueUrl = revealValue !== credential;
209 + const isRevealValueHostedAppPairingUrl = isRevealValueUrl && isHostedAppPairingUrl(revealValue);
210 + const isRevealValueQrShareable =
211 + endpointCopyOptions.find((option) => option.url === revealValue)?.qrShareable ?? true;
212 + const canCopyToClipboard =
213 + typeof window !== "undefined" &&
214 + window.isSecureContext &&
215 + navigator.clipboard?.writeText != null;
216 +
217 + const { copyToClipboard } = useCopyToClipboard<{
218 + value: string;
219 + kind: "code" | "hosted-link" | "link";
220 + }>({
221 + onCopy: ({ kind }) => {
222 + toastManager.add({
223 + type: "success",
224 + title:
225 + kind === "hosted-link"
226 + ? "Hosted app link copied"
227 + : kind === "link"
228 + ? "Pairing URL copied"
229 + : "Pairing code copied",
230 + description:
231 + kind === "hosted-link"
232 + ? "Open it in the browser on the device you want to connect."
233 + : kind === "link"
234 + ? "Open it in the client you want to pair to this environment."
235 + : "Paste it into another client to finish pairing.",
236 + });
237 + },
238 + onError: (error, { value, kind }) => {
239 + // Captured per attempt so concurrent copies cannot make the dialog
240 + // reveal a different value than the one that failed.
241 + setFailedCopyValue(value);
242 + setIsRevealDialogOpen(true);
243 + toastManager.add(
244 + stackedThreadToast({
245 + type: "error",
246 + title: canCopyToClipboard
247 + ? kind === "hosted-link"
248 + ? "Could not copy hosted app link"
249 + : kind === "link"
250 + ? "Could not copy pairing URL"
251 + : "Could not copy pairing code"
252 + : "Clipboard copy unavailable",
253 + description: canCopyToClipboard ? error.message : "Showing the full value instead.",
254 + }),
255 + );
256 + },
257 + });
258 +
259 + const copyPairingValue = (value: string, kind: "code" | "hosted-link" | "link") => {
260 + copyToClipboard(value, { value, kind });
261 + };
262 +
263 + const copyKindForUrl = (url: string): "hosted-link" | "link" =>
264 + isHostedAppPairingUrl(url) ? "hosted-link" : "link";
265 +
266 + const handleCopyCode = () => {
267 + if (credential) copyPairingValue(credential, "code");
268 + };
269 +
270 + const expiresAbsolute = formatAccessTimestamp(pairingLink.expiresAt);
271 +
272 + const primaryLabel = pairingLink.label ?? "Pairing link";
273 + const selectedQrOption = selectQrEndpointOption(
274 + endpointCopyOptions,
275 + qrEndpointId,
276 + defaultEndpointKey,
277 + );
278 + const qrPairingUrl = selectedQrOption?.url ?? shareablePairingUrl;
279 + const canRenderQrForSelection = selectedQrOption?.qrShareable ?? true;
280 + if (expiresAtMs <= nowMs) {
281 + return null;
282 + }
283 +
284 + return (
285 + <div className={accessRowClassName(presentation)}>
286 + <div className={ITEM_ROW_INNER_CLASSNAME}>
287 + <div className="min-w-0 flex-1 space-y-1">
288 + <div className="flex min-h-5 items-center gap-1.5">
289 + <ConnectionStatusDot
290 + tooltipText={`Link created at ${formatAccessTimestamp(pairingLink.createdAt)}`}
291 + dotClassName="bg-warning"
292 + />
293 + <h3 className="text-sm font-medium text-foreground">{primaryLabel}</h3>
294 + </div>
295 + <p className="text-xs text-muted-foreground">
296 + <Tooltip>
297 + <TooltipTrigger render={<span />}>
298 + {formatExpiresInLabel(pairingLink.expiresAt, nowMs)}
299 + </TooltipTrigger>
300 + <TooltipPopup side="top">{expiresAbsolute}</TooltipPopup>
301 + </Tooltip>
302 + <span aria-hidden> · </span>
303 + <AccessScopeSummary scopes={pairingLink.scopes} label="Pairing link scopes" />
304 + </p>
305 + {!credential ? (
306 + <p className="text-2xs text-muted-foreground/70">
307 + Create a new link to share from this client.
308 + </p>
309 + ) : shareablePairingUrl === null ? (
310 + <p className="text-2xs text-muted-foreground/70">
311 + Copy the token and pair from another client using this backend&apos;s reachable host.
312 + </p>
313 + ) : null}
314 + </div>
315 + <div className="flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end">
316 + {shareablePairingUrl && canCopyToClipboard ? (
317 + <Button
318 + size="xs"
319 + variant="outline"
320 + aria-expanded={isQrPanelOpen}
321 + aria-controls={qrPanelId}
322 + onClick={() => setIsQrPanelOpen((open) => !open)}
323 + >
324 + <QrCodeIcon aria-hidden />
325 + Share
326 + </Button>
327 + ) : null}
328 + <Dialog
329 + open={credential !== undefined && isRevealDialogOpen}
330 + onOpenChange={(open) => {
331 + setIsRevealDialogOpen(open);
332 + if (!open) setFailedCopyValue(null);
333 + }}
334 + >
335 + {!credential ? null : canCopyToClipboard ? (
336 + shareablePairingUrl ? null : (
337 + <Button size="xs" variant="outline" onClick={handleCopyCode}>
338 + Copy code
339 + </Button>
340 + )
341 + ) : (
342 + <DialogTrigger render={<Button size="xs" variant="outline" />}>
343 + {shareablePairingUrl ? "Show link" : "Show code"}
344 + </DialogTrigger>
345 + )}
346 + <DialogPopup className="max-w-md">
347 + <DialogHeader>
348 + <DialogTitle>
349 + {isRevealValueUrl
350 + ? isRevealValueHostedAppPairingUrl
351 + ? "Hosted app pairing link"
352 + : "Pairing link"
353 + : "Pairing code"}
354 + </DialogTitle>
355 + <DialogDescription>
356 + {isRevealValueUrl
357 + ? isRevealValueHostedAppPairingUrl
358 + ? "Clipboard copy is unavailable here. Open or manually copy this hosted app link on the device you want to connect."
359 + : "Clipboard copy is unavailable here. Open or manually copy this full pairing URL on the device you want to connect."
360 + : "Clipboard copy is unavailable here. Manually copy this code into another client."}
361 + </DialogDescription>
362 + </DialogHeader>
363 + <DialogPanel>
364 + <Textarea
365 + readOnly
366 + value={revealValue}
367 + rows={isRevealValueUrl ? 4 : 3}
368 + onFocus={(event) => event.currentTarget.select()}
369 + onClick={(event) => event.currentTarget.select()}
370 + />
371 + {isRevealValueUrl && isRevealValueQrShareable ? (
372 + <div className="flex justify-center rounded-xl border border-border/60 bg-muted/30 p-4">
373 + <QRCodeSvg
374 + value={revealValue}
375 + size={132}
376 + level="M"
377 + marginSize={2}
378 + title="Pairing link — scan to open on another device"
379 + />
380 + </div>
381 + ) : null}
382 + </DialogPanel>
383 + <DialogFooter variant="bare">
384 + <Button variant="outline" onClick={() => setIsRevealDialogOpen(false)}>
385 + Done
386 + </Button>
387 + {canCopyToClipboard ? (
388 + <Button variant="outline" onClick={handleCopyCode}>
389 + Copy code
390 + </Button>
391 + ) : null}
392 + </DialogFooter>
393 + </DialogPopup>
394 + </Dialog>
395 + <Button
396 + size="xs"
397 + variant="destructive-outline"
398 + disabled={!canRevoke || revokingPairingLinkId === pairingLink.id}
399 + onClick={() => void onRevoke(pairingLink.id)}
400 + >
401 + {revokingPairingLinkId === pairingLink.id ? "Revoking…" : "Revoke"}
402 + </Button>
403 + </div>
404 + </div>
405 + {isQrPanelOpen && qrPairingUrl !== null ? (
406 + <div
407 + id={qrPanelId}
408 + className="mt-3 flex flex-col gap-4 border-t border-border/50 pt-3 sm:flex-row sm:items-start sm:justify-between"
409 + >
410 + <div className="min-w-0 flex-1 space-y-3">
411 + {endpointCopyOptions.length > 1 ? (
412 + <div
413 + className="space-y-1.5"
414 + role="radiogroup"
415 + aria-label="Endpoint the pairing QR code and URL use"
416 + >
417 + <p className="text-2xs text-muted-foreground/70">Reach this machine via</p>
418 + {endpointCopyOptions.map((option) => {
419 + const isSelected = option.id === selectedQrOption?.id;
420 + return (
421 + <button
422 + key={option.id}
423 + type="button"
424 + role="radio"
425 + aria-checked={isSelected}
426 + className={cn(
427 + "flex w-full items-baseline gap-2 rounded-lg border px-2.5 py-1.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
428 + isSelected
429 + ? "border-foreground/60 bg-muted/30"
430 + : "border-border/50 hover:bg-muted/20",
431 + )}
432 + onClick={() => setQrEndpointId(option.id)}
433 + >
434 + <span
435 + className={cn(
436 + "text-xs font-medium",
437 + isSelected ? "text-foreground" : "text-muted-foreground",
438 + )}
439 + >
440 + {option.label}
441 + </span>
442 + <span className="min-w-0 truncate text-2xs text-muted-foreground/70">
443 + {option.detail}
444 + </span>
445 + </button>
446 + );
447 + })}
448 + </div>
449 + ) : null}
450 + <div className="flex items-center gap-2 rounded-lg border border-border/60 bg-muted/30 px-2.5 py-1.5">
451 + <Tooltip>
452 + <TooltipTrigger
453 + render={
454 + <code className="min-w-0 flex-1 truncate font-mono text-2xs text-muted-foreground">
455 + {qrPairingUrl}
456 + </code>
457 + }
458 + />
459 + <TooltipPopup side="top">{qrPairingUrl}</TooltipPopup>
460 + </Tooltip>
461 + <Button
462 + size="xs"
463 + variant="ghost"
464 + className="shrink-0"
465 + onClick={() => copyPairingValue(qrPairingUrl, copyKindForUrl(qrPairingUrl))}
466 + >
467 + Copy link
468 + </Button>
469 + </div>
470 + <Button size="xs" variant="ghost" onClick={handleCopyCode}>
471 + Copy code only
472 + </Button>
473 + </div>
474 + {canRenderQrForSelection ? (
475 + <div className="w-fit shrink-0 self-center rounded-xl bg-white p-3 sm:self-start">
476 + <QRCodeSvg
477 + value={qrPairingUrl}
478 + size={168}
479 + level="M"
480 + marginSize={1}
481 + title="Pairing link — scan to open on another device"
482 + />
483 + </div>
484 + ) : (
485 + <div className="flex size-[192px] shrink-0 items-center justify-center self-center rounded-xl border border-border/50 p-4 sm:self-start">
486 + <p className="text-center text-2xs text-muted-foreground/70">
487 + No QR for this endpoint. Another device scanning a loopback link would dial itself;
488 + copy the URL for use on this machine instead.
489 + </p>
490 + </div>
491 + )}
492 + </div>
493 + ) : null}
494 + </div>
495 + );
496 +});
497 +
498 +type ConnectedClientListRowProps = {
499 + clientSession: ServerClientSessionRecord;
500 + presentation?: AccessSectionPresentation;
501 + revokingClientSessionId: string | null;
502 + onRevokeSession: (sessionId: ServerClientSessionRecord["sessionId"]) => void;
503 + canRevoke: boolean;
504 +};
505 +
506 +const ConnectedClientListRow = memo(function ConnectedClientListRow({
507 + clientSession,
508 + presentation = "current",
509 + revokingClientSessionId,
510 + onRevokeSession,
511 + canRevoke,
512 +}: ConnectedClientListRowProps) {
513 + const nowMs = useRelativeTimeTick(1_000);
514 + const isLive = clientSession.current || clientSession.connected;
515 + const lastConnectedAt = clientSession.lastConnectedAt;
516 + const statusTooltip = isLive
517 + ? lastConnectedAt
518 + ? `Connected for ${formatElapsedDurationLabel(lastConnectedAt, nowMs)}`
519 + : "Connected"
520 + : lastConnectedAt
521 + ? `Last connected at ${formatAccessTimestamp(lastConnectedAt)}`
522 + : "Not connected yet.";
523 + const deviceInfoBits = [
524 + clientSession.client.deviceType !== "unknown"
525 + ? clientSession.client.deviceType[0]?.toUpperCase() + clientSession.client.deviceType.slice(1)
526 + : null,
527 + clientSession.client.os ?? null,
528 + clientSession.client.browser ?? null,
529 + clientSession.client.ipAddress ?? null,
530 + ].filter((value): value is string => value !== null);
531 + const primaryLabel =
532 + clientSession.client.label ??
533 + ([clientSession.client.os, clientSession.client.browser].filter(Boolean).join(" · ") ||
534 + clientSession.subject);
535 +
536 + return (
537 + <div className={accessRowClassName(presentation)}>
538 + <div className={ITEM_ROW_INNER_CLASSNAME}>
539 + <div className="min-w-0 flex-1 space-y-1">
540 + <div className="flex min-h-5 items-center gap-1.5">
541 + <ConnectionStatusDot
542 + tooltipText={statusTooltip}
543 + dotClassName={isLive ? "bg-success" : "bg-muted-foreground/30"}
544 + pingClassName={isLive ? "bg-success/60 duration-2000" : null}
545 + />
546 + <h3 className="text-sm font-medium text-foreground">{primaryLabel}</h3>
547 + {clientSession.current ? (
548 + <span className="text-3xs text-muted-foreground/80 rounded-md border border-border/50 bg-muted/50 px-1 py-0.5">
549 + This device
550 + </span>
551 + ) : null}
552 + </div>
553 + <p className="text-xs text-muted-foreground">
554 + {deviceInfoBits.length > 0 ? (
555 + <>
556 + {deviceInfoBits.join(" · ")}
557 + <span aria-hidden> · </span>
558 + </>
559 + ) : null}
560 + <AccessScopeSummary scopes={clientSession.scopes} label="Client scopes" />
561 + </p>
562 + </div>
563 + <div className="flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end">
564 + {!clientSession.current ? (
565 + <Button
566 + size="xs"
567 + variant="destructive-outline"
568 + disabled={!canRevoke || revokingClientSessionId === clientSession.sessionId}
569 + onClick={() => void onRevokeSession(clientSession.sessionId)}
570 + >
571 + {revokingClientSessionId === clientSession.sessionId ? "Revoking…" : "Revoke"}
572 + </Button>
573 + ) : null}
574 + </div>
575 + </div>
576 + </div>
577 + );
578 +});
579 +
580 +type AuthorizedClientsHeaderActionProps = {
581 + onPairingLinkCreated: (result: AuthPairingCredentialResult) => void;
582 + clientSessions: ReadonlyArray<ServerClientSessionRecord> | null;
583 + isRevokingOtherClients: boolean;
584 + onRevokeOtherClients: () => void;
585 + delegatableScopes: ReadonlyArray<AuthEnvironmentScope>;
586 +};
587 +
588 +export const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHeaderAction({
589 + onPairingLinkCreated,
590 + clientSessions,
591 + isRevokingOtherClients,
592 + onRevokeOtherClients,
593 + delegatableScopes,
594 +}: AuthorizedClientsHeaderActionProps) {
595 + const primaryEnvironmentId = usePrimaryEnvironmentId();
596 + const [dialogOpen, setDialogOpen] = useState(false);
597 + const [pairingLabel, setPairingLabel] = useState("");
598 + const [pairingScopes, setPairingScopes] = useState<ReadonlyArray<AuthGrantScope>>([
599 + ...AuthStandardClientScopes,
600 + ]);
601 + const selectedScopes = pairingScopes.filter((scope) => delegatableScopes.includes(scope));
602 + const [isCreatingPairingLink, setIsCreatingPairingLink] = useState(false);
603 +
604 + const handleCreatePairingLink = async () => {
605 + if (
606 + primaryEnvironmentId === null ||
607 + selectedScopes.length === 0 ||
608 + !readEnvironmentScope(primaryEnvironmentId, AuthAccessWriteScope) ||
609 + !selectedScopes.every((scope) => readEnvironmentScope(primaryEnvironmentId, scope))
610 + )
611 + return;
612 + setIsCreatingPairingLink(true);
613 + const settled = await settlePromise(async () => {
614 + const created = await createServerPairingCredential({
615 + label: pairingLabel,
616 + scopes: selectedScopes,
617 + });
618 + onPairingLinkCreated(created);
619 + setPairingLabel("");
620 + setPairingScopes(
621 + AuthStandardClientScopes.filter((scope) => delegatableScopes.includes(scope)),
622 + );
623 + setDialogOpen(false);
624 + });
625 + if (settled._tag === "Failure") {
626 + const error = Cause.squash(settled.cause);
627 + const message = error instanceof Error ? error.message : "Failed to create pairing URL.";
628 + toastManager.add(
629 + stackedThreadToast({
630 + type: "error",
631 + title: "Could not create pairing URL",
632 + description: message,
633 + }),
634 + );
635 + }
636 + setIsCreatingPairingLink(false);
637 + };
638 +
639 + const togglePairingScope = (scope: AuthGrantScope, checked: boolean) => {
640 + setPairingScopes((current) => togglePairingScopeSelection(current, scope, checked));
641 + };
642 +
643 + return (
644 + <div className="flex items-center gap-2">
645 + <Button
646 + size="xs"
647 + variant="destructive-outline"
648 + disabled={isRevokingOtherClients || !canRevokeOtherClients(clientSessions)}
649 + onClick={() => void onRevokeOtherClients()}
650 + >
651 + {isRevokingOtherClients ? "Revoking…" : "Revoke others"}
652 + </Button>
653 + <Dialog
654 + open={dialogOpen}
655 + onOpenChange={(open) => {
656 + setDialogOpen(open);
657 + if (!open) {
658 + setPairingLabel("");
659 + setPairingScopes(
660 + AuthStandardClientScopes.filter((scope) => delegatableScopes.includes(scope)),
661 + );
662 + }
663 + }}
664 + >
665 + <DialogTrigger
666 + render={
667 + <Button size="xs" variant="default">
668 + <PlusIcon className="size-3" />
669 + Create link
670 + </Button>
671 + }
672 + />
673 + <DialogPopup className="max-w-md">
674 + <DialogHeader>
675 + <DialogTitle>Create pairing link</DialogTitle>
676 + <DialogDescription>
677 + Generate a one-time link that another device can use to pair with this backend as an
678 + authorized client.
679 + </DialogDescription>
680 + </DialogHeader>
681 + <DialogPanel>
682 + <label className="block">
683 + <span className="mb-1.5 block text-xs font-medium text-foreground">
684 + Client label (optional)
685 + </span>
686 + <Input
687 + value={pairingLabel}
688 + onChange={(event) => setPairingLabel(event.target.value)}
689 + placeholder="e.g. Living room iPad"
690 + disabled={isCreatingPairingLink}
691 + autoFocus
692 + />
693 + </label>
694 + <section className="space-y-3">
695 + <div className="flex items-center justify-between gap-3">
696 + <div>
697 + <h3 className="text-xs font-medium text-foreground">Permissions</h3>
698 + <p className="text-xs text-muted-foreground">
699 + Limit what the paired client can do.
700 + </p>
701 + </div>
702 + <div className="flex gap-1">
703 + <Button
704 + size="xs"
705 + variant="outline"
706 + disabled={isCreatingPairingLink}
707 + onClick={() =>
708 + setPairingScopes(
709 + [
710 + AuthOrchestrationReadScope,
711 + AuthFilesystemReadScope,
712 + AuthDiagnosticsReadScope,
713 + AuthTerminalReadScope,
714 + ].filter((scope) => delegatableScopes.includes(scope)),
715 + )
716 + }
717 + >
718 + Read only
719 + </Button>
720 + <Button
721 + size="xs"
722 + variant="outline"
723 + disabled={isCreatingPairingLink}
724 + onClick={() =>
725 + setPairingScopes(
726 + AuthStandardClientScopes.filter((scope) =>
727 + delegatableScopes.includes(scope),
728 + ),
729 + )
730 + }
731 + >
732 + Standard
733 + </Button>
734 + </div>
735 + </div>
736 + <div className="divide-y divide-border/60 rounded-lg border border-input bg-muted/25">
737 + {PAIRING_SCOPE_OPTIONS.filter(({ scope }) => delegatableScopes.includes(scope)).map(
738 + ({ scope, title, description }) => (
739 + <label
740 + key={scope}
741 + className="flex cursor-pointer items-start gap-3 px-3 py-2.5 transition-colors hover:bg-muted/40"
742 + >
743 + <Checkbox
744 + className="mt-0.5"
745 + checked={pairingScopes.includes(scope)}
746 + disabled={isCreatingPairingLink}
747 + onCheckedChange={(checked) => togglePairingScope(scope, checked === true)}
748 + />
749 + <span className="min-w-0">
750 + <span className="block text-xs font-medium text-foreground">{title}</span>
751 + <span className="block text-xs leading-snug text-muted-foreground">
752 + {description}
753 + </span>
754 + </span>
755 + </label>
756 + ),
757 + )}
758 + </div>
759 + {selectedScopes.length === 0 ? (
760 + <p className="text-xs text-destructive">Select at least one permission.</p>
761 + ) : selectedScopes.includes(AuthAccessWriteScope) ? (
762 + <p className="text-xs text-warning">
763 + This client can create or revoke access for other devices.
764 + </p>
765 + ) : null}
766 + </section>
767 + </DialogPanel>
768 + <DialogFooter variant="bare">
769 + <Button
770 + variant="outline"
771 + disabled={isCreatingPairingLink}
772 + onClick={() => setDialogOpen(false)}
773 + >
774 + Cancel
775 + </Button>
776 + <Button
777 + disabled={isCreatingPairingLink || selectedScopes.length === 0}
778 + onClick={() => void handleCreatePairingLink()}
779 + >
780 + {isCreatingPairingLink ? "Creating…" : "Create link"}
781 + </Button>
782 + </DialogFooter>
783 + </DialogPopup>
784 + </Dialog>
785 + </div>
786 + );
787 +});
788 +
789 +type PairingClientsListProps = {
790 + endpointUrl: string | null | undefined;
791 + endpoints: ReadonlyArray<AdvertisedEndpoint>;
792 + defaultEndpointKey: string | null;
793 + presentation?: AccessSectionPresentation;
794 + isLoading: boolean;
795 + pairingLinks: ReadonlyArray<ServerPairingLinkRecord>;
796 + createdPairingCredentials: ReadonlyMap<string, string>;
797 + clientSessions: ReadonlyArray<ServerClientSessionRecord>;
798 + revokingPairingLinkId: string | null;
799 + revokingClientSessionId: string | null;
800 + onRevokePairingLink: (id: string) => void;
801 + onRevokeClientSession: (sessionId: ServerClientSessionRecord["sessionId"]) => void;
802 + canRevoke: boolean;
803 +};
804 +
805 +export const PairingClientsList = memo(function PairingClientsList({
806 + endpointUrl,
807 + endpoints,
808 + defaultEndpointKey,
809 + presentation = "current",
810 + isLoading,
811 + pairingLinks,
812 + createdPairingCredentials,
813 + clientSessions,
814 + revokingPairingLinkId,
815 + revokingClientSessionId,
816 + onRevokePairingLink,
817 + onRevokeClientSession,
818 + canRevoke,
819 +}: PairingClientsListProps) {
820 + return (
821 + <>
822 + {pairingLinks.map((pairingLink) => (
823 + <PairingLinkListRow
824 + key={pairingLink.id}
825 + pairingLink={pairingLink}
826 + credential={createdPairingCredentials.get(pairingLink.id)}
827 + endpointUrl={endpointUrl}
828 + endpoints={endpoints}
829 + defaultEndpointKey={defaultEndpointKey}
830 + presentation={presentation}
831 + revokingPairingLinkId={revokingPairingLinkId}
832 + onRevoke={onRevokePairingLink}
833 + canRevoke={canRevoke}
834 + />
835 + ))}
836 +
837 + {clientSessions.map((clientSession) => (
838 + <ConnectedClientListRow
839 + key={clientSession.sessionId}
840 + clientSession={clientSession}
841 + presentation={presentation}
842 + revokingClientSessionId={revokingClientSessionId}
843 + onRevokeSession={onRevokeClientSession}
844 + canRevoke={canRevoke}
845 + />
846 + ))}
847 +
848 + {pairingLinks.length === 0 && clientSessions.length === 0 && !isLoading ? (
849 + <div className={accessRowClassName(presentation)}>
850 + <p className="text-xs text-muted-foreground/60">No pairing links or client sessions.</p>
851 + </div>
852 + ) : null}
853 + </>
854 + );
855 +});
856 +
857 +type AdvertisedEndpointListRowProps = {
858 + endpoint: AdvertisedEndpoint;
859 + isDefault: boolean;
860 + presentation?: AccessSectionPresentation;
861 + onSetDefault: (endpoint: AdvertisedEndpoint) => void;
862 + onSetupTailscaleServe: (endpoint: AdvertisedEndpoint) => void;
863 + onDisableTailscaleServe: (endpoint: AdvertisedEndpoint) => void;
864 + isUpdatingTailscaleServe: boolean;
865 +};
866 +
867 +export const AdvertisedEndpointListRow = memo(function AdvertisedEndpointListRow({
868 + endpoint,
869 + isDefault,
870 + presentation = "current",
871 + onSetDefault,
872 + onSetupTailscaleServe,
873 + onDisableTailscaleServe,
874 + isUpdatingTailscaleServe,
875 +}: AdvertisedEndpointListRowProps) {
876 + const isAvailable = endpoint.status === "available";
877 + const needsTailscaleSetup = isTailscaleHttpsEndpoint(endpoint) && endpoint.status !== "available";
878 + const canDisableTailscaleServe =
879 + isTailscaleHttpsEndpoint(endpoint) && endpoint.status === "available";
880 + const shouldShowEndpointUrl = !needsTailscaleSetup;
881 + const isEndpointRail = presentation === "endpoint-rail";
882 + return (
883 + <div className={endpointRowClassName(presentation, isAvailable)}>
884 + {isEndpointRail && isDefault ? (
885 + <span className="absolute inset-y-2 left-0 w-1 rounded-r-full bg-primary" aria-hidden />
886 + ) : null}
887 + <div className="flex min-h-6 min-w-0 flex-col gap-2 sm:-my-0.5 sm:flex-row sm:items-center">
888 + <div className="flex min-w-0 items-baseline gap-3">
889 + <h3 className="shrink-0 text-sm leading-5 font-medium text-foreground">
890 + {endpoint.label}
891 + </h3>
892 + {shouldShowEndpointUrl ? (
893 + <Tooltip>
894 + <TooltipTrigger
895 + render={
896 + <p className="min-w-0 truncate text-xs leading-5 text-muted-foreground">
897 + {endpoint.httpBaseUrl}
898 + </p>
899 + }
900 + />
901 + <TooltipPopup side="top">{endpoint.httpBaseUrl}</TooltipPopup>
902 + </Tooltip>
903 + ) : null}
904 + {!isAvailable ? (
905 + <span className="shrink-0 rounded-md border border-border/70 px-1 py-0.5 text-3xs text-muted-foreground">
906 + Setup required
907 + </span>
908 + ) : null}
909 + </div>
910 + <div className="ml-auto flex min-h-6 shrink-0 items-center justify-end gap-2">
911 + {isDefault ? (
912 + <span className="rounded-md border border-primary/30 bg-primary/10 px-1 py-0.5 text-3xs text-primary">
913 + Default
914 + </span>
915 + ) : null}
916 + {needsTailscaleSetup ? (
917 + <Button
918 + size="xs"
919 + variant="outline"
920 + onClick={() => onSetupTailscaleServe(endpoint)}
921 + disabled={isUpdatingTailscaleServe}
922 + >
923 + {isUpdatingTailscaleServe ? "Restarting…" : "Setup"}
924 + </Button>
925 + ) : null}
926 + {canDisableTailscaleServe ? (
927 + <Button
928 + size="xs"
929 + variant="destructive-outline"
930 + onClick={() => onDisableTailscaleServe(endpoint)}
931 + disabled={isUpdatingTailscaleServe}
932 + >
933 + {isUpdatingTailscaleServe ? "Restarting…" : "Disable"}
934 + </Button>
935 + ) : null}
936 + {!needsTailscaleSetup && !isDefault ? (
937 + <Button size="xs" variant="outline" onClick={() => onSetDefault(endpoint)}>
938 + Set as default
939 + </Button>
940 + ) : null}
941 + </div>
942 + </div>
943 + </div>
944 + );
945 +});
946 +
947 +export function NetworkAccessDescription({
948 + endpoint,
949 + hiddenEndpointCount,
950 + expanded,
951 + onToggleExpanded,
952 + fallback,
953 +}: {
954 + endpoint: AdvertisedEndpoint | null;
955 + hiddenEndpointCount: number;
956 + expanded: boolean;
957 + onToggleExpanded: () => void;
958 + fallback: ReactNode;
959 +}) {
960 + if (!endpoint) {
961 + return fallback;
962 + }
963 +
964 + const summary = (
965 + <>
966 + <span className="min-w-0 truncate">{endpoint.httpBaseUrl}</span>
967 + {hiddenEndpointCount > 0 ? (
968 + <span className="shrink-0 text-xs font-medium">
969 + {expanded ? "Hide" : `+${hiddenEndpointCount}`}
970 + </span>
971 + ) : null}
972 + </>
973 + );
974 +
975 + return (
976 + <span className="inline-flex min-w-0 max-w-full items-baseline gap-1">
977 + <span className="shrink-0">Reachable at</span>
978 + {hiddenEndpointCount > 0 ? (
979 + <button
980 + type="button"
981 + className="inline-flex min-w-0 max-w-full items-baseline gap-2 border-b border-dotted border-muted-foreground/60 text-left text-muted-foreground underline-offset-4 hover:border-foreground hover:text-foreground"
982 + onClick={onToggleExpanded}
983 + aria-expanded={expanded}
984 + >
985 + {summary}
986 + </button>
987 + ) : (
988 + <span className="inline-flex min-w-0 max-w-full items-baseline gap-2">{summary}</span>
989 + )}
990 + </span>
991 + );
992 +}
apps/web/src/components/settings/ConnectionsSettings.tsx
+9 -962
@@ -1,11 +1,9 @@
1 import { SessionPermissions } from "./SessionPermissions";
2 -import { AUTH_SCOPE_OPTIONS as PAIRING_SCOPE_OPTIONS } from "@t3tools/shared/authScopeOptions";
2 import {
3 ChevronRightIcon,
4 ChevronsLeftRightEllipsisIcon,
5 EllipsisIcon,
6 PlusIcon,
8 - QrCodeIcon,
7 RouteIcon,
8 TerminalIcon,
9 } from "lucide-react";
@@ -13,10 +11,8 @@ import { useAtomValue } from "@effect/atom-react";
11 import {
12 type KeyboardEvent,
13 type ReactNode,
16 - memo,
14 useEffect,
15 useEffectEvent,
19 - useId,
16 useRef,
17 useState,
18 } from "react";
@@ -24,16 +20,9 @@ import {
20 AuthAccessReadScope,
21 AuthAccessWriteScope,
22 AuthEnvironmentMaintainScope,
27 - AuthDiagnosticsReadScope,
28 - AuthOrchestrationReadScope,
23 AuthRelayReadScope,
24 AuthRelayWriteScope,
31 - AuthFilesystemReadScope,
32 - AuthStandardClientScopes,
33 - AuthTerminalReadScope,
25 type AuthClientSession,
35 - type AuthEnvironmentScope,
36 - type AuthGrantScope,
26 type AuthPairingLink,
27 type AuthPairingCredentialResult,
28 type AdvertisedEndpoint,
@@ -65,24 +54,13 @@ import * as Option from "effect/Option";
54 import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
55 import { cn } from "../../lib/utils";
56 import { isLocalEnvironmentDisabled } from "../../localEnvironment";
68 -import { formatElapsedDurationLabel, formatExpiresInLabel } from "../../timestampFormat";
69 -import { resolveDesktopPairingUrl, resolveHostedPairingUrl } from "./pairingUrls";
57 import {
58 applyWslEnableSelection,
72 - canRevokeOtherClients,
73 - isQrShareableEndpoint,
59 isWslSettingsRowVisible,
60 missingTailscaleEndpointDescription,
61 resolveLocalVersionStatusLabel,
77 - selectQrEndpointOption,
78 - togglePairingScopeSelection,
62 } from "./ConnectionsSettings.logic";
80 -import {
81 - SettingsPageContainer,
82 - SettingsRow,
83 - SettingsSection,
84 - useRelativeTimeTick,
85 -} from "./settingsLayout";
63 +import { SettingsPageContainer, SettingsRow, SettingsSection } from "./settingsLayout";
64 import { LocalEnvironmentSetting } from "./LocalEnvironmentSetting";
65 import { searchableSetting } from "./settingsSearch";
66 import { EnvironmentIconMenu } from "./EnvironmentIconPicker";
@@ -111,7 +89,6 @@ import {
89 AutocompleteList,
90 AutocompletePopup,
91 } from "../ui/autocomplete";
114 -import { Checkbox } from "../ui/checkbox";
92 import {
93 Dialog,
94 DialogClose,
@@ -133,8 +110,6 @@ import {
110 AlertDialogPopup,
111 AlertDialogTitle,
112 } from "../ui/alert-dialog";
136 -import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
137 -import { QRCodeSvg } from "../ui/qr-code";
113 import { Spinner } from "../ui/spinner";
114 import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
115 import { Menu, MenuItem, MenuPopup, MenuSeparator, MenuTrigger } from "../ui/menu";
@@ -146,16 +121,12 @@ import { Button } from "../ui/button";
121 import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "../ui/empty";
122 import { AnimatedHeight } from "../AnimatedHeight";
123 import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
149 -import { Textarea } from "../ui/textarea";
124 import {
151 - createServerPairingCredential,
125 revokeOtherServerClientSessions,
126 revokeServerClientSession,
127 revokeServerPairingLink,
155 - isLoopbackHostname,
128 usePrimarySessionState,
129 type ServerClientSessionRecord,
158 - type ServerPairingLinkRecord,
130 } from "~/environments/primary";
131 import { isDesktopLocalConnectionTarget } from "~/connection/desktopLocal";
132 import { useUiStateStore } from "~/uiStateStore";
@@ -199,7 +170,6 @@ import {
170 primaryServerKeybindingsAtom,
171 serverEnvironment,
172 } from "~/state/server";
202 -import { ConnectionStatusDot } from "../ConnectionStatusDot";
173 import {
174 OutdatedServerUpdateAction,
175 ServerUpdateAction,
@@ -208,7 +178,6 @@ import {
178 type ServerUpdateTarget,
179 } from "../ServerUpdateAction";
180 import { CloudEnvironmentConnectRows } from "../cloud/CloudEnvironmentConnectList";
211 -import { ITEM_ROW_CLASSNAME, ITEM_ROW_INNER_CLASSNAME } from "./itemRows";
181 import {
182 resolveShortcutCommand,
183 shortcutLabelForCommand,
@@ -216,7 +185,6 @@ import {
185 threadJumpIndexFromCommand,
186 } from "../../keybindings";
187 import {
219 - formatAccessTimestamp,
188 parseManualDesktopSshTarget,
189 parsePairingUrlFields,
190 parseRemotePairingFields,
@@ -229,11 +197,15 @@ import {
197 selectPairingEndpoint,
198 isTailscaleHttpsEndpoint,
199 endpointDefaultPreferenceKey,
232 - resolveAdvertisedEndpointPairingUrl,
233 - resolveCurrentOriginPairingUrl,
234 - isHostedAppPairingUrl,
235 - endpointShareHint,
200 } from "./ConnectionsSettings.logic";
201 +import {
202 + type AccessSectionPresentation,
203 + accessRowClassName,
204 + AdvertisedEndpointListRow,
205 + AuthorizedClientsHeaderAction,
206 + NetworkAccessDescription,
207 + PairingClientsList,
208 +} from "./AuthorizedClientsSettings";
209
210 const DEFAULT_TAILSCALE_SERVE_PORT = 443;
211 const EMPTY_ADVERTISED_ENDPOINTS: ReadonlyArray<AdvertisedEndpoint> = [];
@@ -245,931 +217,6 @@ const EMPTY_DISCOVERED_SSH_HOSTS: ReadonlyArray<DesktopDiscoveredSshHost> = [];
217 const BACKEND_VALUE_DEFAULT_WSL = "backend:default-wsl";
218 const BACKEND_VALUE_WSL_OFF = "backend:wsl-off";
219
248 -function AccessScopeSummary({
249 - scopes,
250 - label,
251 -}: {
252 - readonly scopes: ReadonlyArray<AuthEnvironmentScope>;
253 - readonly label: string;
254 -}) {
255 - const scopeCountLabel = `${scopes.length} ${scopes.length === 1 ? "scope" : "scopes"}`;
256 -
257 - return (
258 - <Popover>
259 - <PopoverTrigger
260 - openOnHover
261 - delay={250}
262 - closeDelay={100}
263 - render={
264 - <button
265 - type="button"
266 - aria-label={`${label}: show ${scopeCountLabel}`}
267 - className="cursor-help underline decoration-border underline-offset-2 outline-hidden hover:text-foreground focus-visible:text-foreground"
268 - />
269 - }
270 - >
271 - {scopeCountLabel}
272 - </PopoverTrigger>
273 - <PopoverPopup
274 - side="top"
275 - align="start"
276 - tooltipStyle
277 - className="w-max max-w-80 whitespace-normal"
278 - >
279 - <p className="mb-1 font-medium">Granted scopes</p>
280 - <div className="flex flex-col gap-0.5">
281 - {scopes.map((scope) => (
282 - <code key={scope} className="font-mono text-foreground/85">
283 - {scope}
284 - </code>
285 - ))}
286 - </div>
287 - </PopoverPopup>
288 - </Popover>
289 - );
290 -}
291 -
292 -const ENDPOINT_ROW_CLASSNAME = "first:rounded-t-xl last:rounded-b-xl px-3 py-2.5 sm:px-4";
293 -
294 -type AccessSectionPresentation = "current" | "endpoint-rail";
295 -
296 -function accessRowClassName(_presentation: AccessSectionPresentation) {
297 - return ITEM_ROW_CLASSNAME;
298 -}
299 -
300 -function endpointRowClassName(presentation: AccessSectionPresentation, isAvailable: boolean) {
301 - if (presentation === "endpoint-rail") {
302 - return cn(
303 - "relative first:rounded-t-xl last:rounded-b-xl px-3 py-3 sm:px-4",
304 - !isAvailable && "bg-muted/15",
305 - );
306 - }
307 -
308 - return cn(ENDPOINT_ROW_CLASSNAME, !isAvailable && "bg-muted/24");
309 -}
310 -
311 -type PairingLinkListRowProps = {
312 - pairingLink: ServerPairingLinkRecord;
313 - credential: string | undefined;
314 - endpointUrl: string | null | undefined;
315 - endpoints: ReadonlyArray<AdvertisedEndpoint>;
316 - defaultEndpointKey: string | null;
317 - presentation?: AccessSectionPresentation;
318 - revokingPairingLinkId: string | null;
319 - onRevoke: (id: string) => void;
320 - canRevoke: boolean;
321 -};
322 -
323 -const PairingLinkListRow = memo(function PairingLinkListRow({
324 - pairingLink,
325 - credential,
326 - endpointUrl,
327 - endpoints,
328 - defaultEndpointKey,
329 - presentation = "current",
330 - revokingPairingLinkId,
331 - onRevoke,
332 - canRevoke,
333 -}: PairingLinkListRowProps) {
334 - const nowMs = useRelativeTimeTick(1_000);
335 - const expiresAtMs = new Date(pairingLink.expiresAt).getTime();
336 - const [isRevealDialogOpen, setIsRevealDialogOpen] = useState(false);
337 - const [isQrPanelOpen, setIsQrPanelOpen] = useState(false);
338 - const [qrEndpointId, setQrEndpointId] = useState<string | null>(null);
339 - const qrPanelId = useId();
340 -
341 - const currentOriginPairingUrl = credential ? resolveCurrentOriginPairingUrl(credential) : null;
342 - const hostedPairingUrl =
343 - credential && endpointUrl != null && endpointUrl !== ""
344 - ? resolveHostedPairingUrl(endpointUrl, credential)
345 - : null;
346 - const endpointPairingUrl = (() => {
347 - const endpoint = selectPairingEndpoint(endpoints, defaultEndpointKey);
348 - return endpoint && credential
349 - ? resolveAdvertisedEndpointPairingUrl(endpoint, credential)
350 - : null;
351 - })();
352 - const endpointCopyOptions = (() => {
353 - const options: Array<{
354 - readonly id: string;
355 - readonly preferenceKey: string;
356 - readonly label: string;
357 - readonly url: string;
358 - readonly detail: string;
359 - readonly qrShareable: boolean;
360 - }> = [];
361 - if (!credential) return options;
362 - for (const endpoint of endpoints) {
363 - if (endpoint.status === "unavailable") {
364 - continue;
365 - }
366 - const url = resolveAdvertisedEndpointPairingUrl(endpoint, credential);
367 - options.push({
368 - id: endpoint.id,
369 - preferenceKey: endpointDefaultPreferenceKey(endpoint),
370 - label: endpoint.label,
371 - url,
372 - detail: endpointShareHint(endpoint, url),
373 - qrShareable: isQrShareableEndpoint(endpoint),
374 - });
375 - }
376 - return options;
377 - })();
378 - const shareablePairingUrl =
379 - endpointPairingUrl ??
380 - (credential && endpointUrl != null && endpointUrl !== ""
381 - ? (hostedPairingUrl ?? resolveDesktopPairingUrl(endpointUrl, credential))
382 - : isLoopbackHostname(window.location.hostname)
383 - ? null
384 - : currentOriginPairingUrl);
385 - const [failedCopyValue, setFailedCopyValue] = useState<string | null>(null);
386 - const revealValue = failedCopyValue ?? shareablePairingUrl ?? credential ?? "";
387 - const isRevealValueUrl = revealValue !== credential;
388 - const isRevealValueHostedAppPairingUrl = isRevealValueUrl && isHostedAppPairingUrl(revealValue);
389 - const isRevealValueQrShareable =
390 - endpointCopyOptions.find((option) => option.url === revealValue)?.qrShareable ?? true;
391 - const canCopyToClipboard =
392 - typeof window !== "undefined" &&
393 - window.isSecureContext &&
394 - navigator.clipboard?.writeText != null;
395 -
396 - const { copyToClipboard } = useCopyToClipboard<{
397 - value: string;
398 - kind: "code" | "hosted-link" | "link";
399 - }>({
400 - onCopy: ({ kind }) => {
401 - toastManager.add({
402 - type: "success",
403 - title:
404 - kind === "hosted-link"
405 - ? "Hosted app link copied"
406 - : kind === "link"
407 - ? "Pairing URL copied"
408 - : "Pairing code copied",
409 - description:
410 - kind === "hosted-link"
411 - ? "Open it in the browser on the device you want to connect."
412 - : kind === "link"
413 - ? "Open it in the client you want to pair to this environment."
414 - : "Paste it into another client to finish pairing.",
415 - });
416 - },
417 - onError: (error, { value, kind }) => {
418 - // Captured per attempt so concurrent copies cannot make the dialog
419 - // reveal a different value than the one that failed.
420 - setFailedCopyValue(value);
421 - setIsRevealDialogOpen(true);
422 - toastManager.add(
423 - stackedThreadToast({
424 - type: "error",
425 - title: canCopyToClipboard
426 - ? kind === "hosted-link"
427 - ? "Could not copy hosted app link"
428 - : kind === "link"
429 - ? "Could not copy pairing URL"
430 - : "Could not copy pairing code"
431 - : "Clipboard copy unavailable",
432 - description: canCopyToClipboard ? error.message : "Showing the full value instead.",
433 - }),
434 - );
435 - },
436 - });
437 -
438 - const copyPairingValue = (value: string, kind: "code" | "hosted-link" | "link") => {
439 - copyToClipboard(value, { value, kind });
440 - };
441 -
442 - const copyKindForUrl = (url: string): "hosted-link" | "link" =>
443 - isHostedAppPairingUrl(url) ? "hosted-link" : "link";
444 -
445 - const handleCopyCode = () => {
446 - if (credential) copyPairingValue(credential, "code");
447 - };
448 -
449 - const expiresAbsolute = formatAccessTimestamp(pairingLink.expiresAt);
450 -
451 - const primaryLabel = pairingLink.label ?? "Pairing link";
452 - const selectedQrOption = selectQrEndpointOption(
453 - endpointCopyOptions,
454 - qrEndpointId,
455 - defaultEndpointKey,
456 - );
457 - const qrPairingUrl = selectedQrOption?.url ?? shareablePairingUrl;
458 - const canRenderQrForSelection = selectedQrOption?.qrShareable ?? true;
459 - if (expiresAtMs <= nowMs) {
460 - return null;
461 - }
462 -
463 - return (
464 - <div className={accessRowClassName(presentation)}>
465 - <div className={ITEM_ROW_INNER_CLASSNAME}>
466 - <div className="min-w-0 flex-1 space-y-1">
467 - <div className="flex min-h-5 items-center gap-1.5">
468 - <ConnectionStatusDot
469 - tooltipText={`Link created at ${formatAccessTimestamp(pairingLink.createdAt)}`}
470 - dotClassName="bg-warning"
471 - />
472 - <h3 className="text-sm font-medium text-foreground">{primaryLabel}</h3>
473 - </div>
474 - <p className="text-xs text-muted-foreground">
475 - <Tooltip>
476 - <TooltipTrigger render={<span />}>
477 - {formatExpiresInLabel(pairingLink.expiresAt, nowMs)}
478 - </TooltipTrigger>
479 - <TooltipPopup side="top">{expiresAbsolute}</TooltipPopup>
480 - </Tooltip>
481 - <span aria-hidden> · </span>
482 - <AccessScopeSummary scopes={pairingLink.scopes} label="Pairing link scopes" />
483 - </p>
484 - {!credential ? (
485 - <p className="text-2xs text-muted-foreground/70">
486 - Create a new link to share from this client.
487 - </p>
488 - ) : shareablePairingUrl === null ? (
489 - <p className="text-2xs text-muted-foreground/70">
490 - Copy the token and pair from another client using this backend&apos;s reachable host.
491 - </p>
492 - ) : null}
493 - </div>
494 - <div className="flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end">
495 - {shareablePairingUrl && canCopyToClipboard ? (
496 - <Button
497 - size="xs"
498 - variant="outline"
499 - aria-expanded={isQrPanelOpen}
500 - aria-controls={qrPanelId}
501 - onClick={() => setIsQrPanelOpen((open) => !open)}
502 - >
503 - <QrCodeIcon aria-hidden />
504 - Share
505 - </Button>
506 - ) : null}
507 - <Dialog
508 - open={credential !== undefined && isRevealDialogOpen}
509 - onOpenChange={(open) => {
510 - setIsRevealDialogOpen(open);
511 - if (!open) setFailedCopyValue(null);
512 - }}
513 - >
514 - {!credential ? null : canCopyToClipboard ? (
515 - shareablePairingUrl ? null : (
516 - <Button size="xs" variant="outline" onClick={handleCopyCode}>
517 - Copy code
518 - </Button>
519 - )
520 - ) : (
521 - <DialogTrigger render={<Button size="xs" variant="outline" />}>
522 - {shareablePairingUrl ? "Show link" : "Show code"}
523 - </DialogTrigger>
524 - )}
525 - <DialogPopup className="max-w-md">
526 - <DialogHeader>
527 - <DialogTitle>
528 - {isRevealValueUrl
529 - ? isRevealValueHostedAppPairingUrl
530 - ? "Hosted app pairing link"
531 - : "Pairing link"
532 - : "Pairing code"}
533 - </DialogTitle>
534 - <DialogDescription>
535 - {isRevealValueUrl
536 - ? isRevealValueHostedAppPairingUrl
537 - ? "Clipboard copy is unavailable here. Open or manually copy this hosted app link on the device you want to connect."
538 - : "Clipboard copy is unavailable here. Open or manually copy this full pairing URL on the device you want to connect."
539 - : "Clipboard copy is unavailable here. Manually copy this code into another client."}
540 - </DialogDescription>
541 - </DialogHeader>
542 - <DialogPanel>
543 - <Textarea
544 - readOnly
545 - value={revealValue}
546 - rows={isRevealValueUrl ? 4 : 3}
547 - onFocus={(event) => event.currentTarget.select()}
548 - onClick={(event) => event.currentTarget.select()}
549 - />
550 - {isRevealValueUrl && isRevealValueQrShareable ? (
551 - <div className="flex justify-center rounded-xl border border-border/60 bg-muted/30 p-4">
552 - <QRCodeSvg
553 - value={revealValue}
554 - size={132}
555 - level="M"
556 - marginSize={2}
557 - title="Pairing link — scan to open on another device"
558 - />
559 - </div>
560 - ) : null}
561 - </DialogPanel>
562 - <DialogFooter variant="bare">
563 - <Button variant="outline" onClick={() => setIsRevealDialogOpen(false)}>
564 - Done
565 - </Button>
566 - {canCopyToClipboard ? (
567 - <Button variant="outline" onClick={handleCopyCode}>
568 - Copy code
569 - </Button>
570 - ) : null}
571 - </DialogFooter>
572 - </DialogPopup>
573 - </Dialog>
574 - <Button
575 - size="xs"
576 - variant="destructive-outline"
577 - disabled={!canRevoke || revokingPairingLinkId === pairingLink.id}
578 - onClick={() => void onRevoke(pairingLink.id)}
579 - >
580 - {revokingPairingLinkId === pairingLink.id ? "Revoking…" : "Revoke"}
581 - </Button>
582 - </div>
583 - </div>
584 - {isQrPanelOpen && qrPairingUrl !== null ? (
585 - <div
586 - id={qrPanelId}
587 - className="mt-3 flex flex-col gap-4 border-t border-border/50 pt-3 sm:flex-row sm:items-start sm:justify-between"
588 - >
589 - <div className="min-w-0 flex-1 space-y-3">
590 - {endpointCopyOptions.length > 1 ? (
591 - <div
592 - className="space-y-1.5"
593 - role="radiogroup"
594 - aria-label="Endpoint the pairing QR code and URL use"
595 - >
596 - <p className="text-2xs text-muted-foreground/70">Reach this machine via</p>
597 - {endpointCopyOptions.map((option) => {
598 - const isSelected = option.id === selectedQrOption?.id;
599 - return (
600 - <button
601 - key={option.id}
602 - type="button"
603 - role="radio"
604 - aria-checked={isSelected}
605 - className={cn(
606 - "flex w-full items-baseline gap-2 rounded-lg border px-2.5 py-1.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
607 - isSelected
608 - ? "border-foreground/60 bg-muted/30"
609 - : "border-border/50 hover:bg-muted/20",
610 - )}
611 - onClick={() => setQrEndpointId(option.id)}
612 - >
613 - <span
614 - className={cn(
615 - "text-xs font-medium",
616 - isSelected ? "text-foreground" : "text-muted-foreground",
617 - )}
618 - >
619 - {option.label}
620 - </span>
621 - <span className="min-w-0 truncate text-2xs text-muted-foreground/70">
622 - {option.detail}
623 - </span>
624 - </button>
625 - );
626 - })}
627 - </div>
628 - ) : null}
629 - <div className="flex items-center gap-2 rounded-lg border border-border/60 bg-muted/30 px-2.5 py-1.5">
630 - <Tooltip>
631 - <TooltipTrigger
632 - render={
633 - <code className="min-w-0 flex-1 truncate font-mono text-2xs text-muted-foreground">
634 - {qrPairingUrl}
635 - </code>
636 - }
637 - />
638 - <TooltipPopup side="top">{qrPairingUrl}</TooltipPopup>
639 - </Tooltip>
640 - <Button
641 - size="xs"
642 - variant="ghost"
643 - className="shrink-0"
644 - onClick={() => copyPairingValue(qrPairingUrl, copyKindForUrl(qrPairingUrl))}
645 - >
646 - Copy link
647 - </Button>
648 - </div>
649 - <Button size="xs" variant="ghost" onClick={handleCopyCode}>
650 - Copy code only
651 - </Button>
652 - </div>
653 - {canRenderQrForSelection ? (
654 - <div className="w-fit shrink-0 self-center rounded-xl bg-white p-3 sm:self-start">
655 - <QRCodeSvg
656 - value={qrPairingUrl}
657 - size={168}
658 - level="M"
659 - marginSize={1}
660 - title="Pairing link — scan to open on another device"
661 - />
662 - </div>
663 - ) : (
664 - <div className="flex size-[192px] shrink-0 items-center justify-center self-center rounded-xl border border-border/50 p-4 sm:self-start">
665 - <p className="text-center text-2xs text-muted-foreground/70">
666 - No QR for this endpoint. Another device scanning a loopback link would dial itself;
667 - copy the URL for use on this machine instead.
668 - </p>
669 - </div>
670 - )}
671 - </div>
672 - ) : null}
673 - </div>
674 - );
675 -});
676 -
677 -type ConnectedClientListRowProps = {
678 - clientSession: ServerClientSessionRecord;
679 - presentation?: AccessSectionPresentation;
680 - revokingClientSessionId: string | null;
681 - onRevokeSession: (sessionId: ServerClientSessionRecord["sessionId"]) => void;
682 - canRevoke: boolean;
683 -};
684 -
685 -const ConnectedClientListRow = memo(function ConnectedClientListRow({
686 - clientSession,
687 - presentation = "current",
688 - revokingClientSessionId,
689 - onRevokeSession,
690 - canRevoke,
691 -}: ConnectedClientListRowProps) {
692 - const nowMs = useRelativeTimeTick(1_000);
693 - const isLive = clientSession.current || clientSession.connected;
694 - const lastConnectedAt = clientSession.lastConnectedAt;
695 - const statusTooltip = isLive
696 - ? lastConnectedAt
697 - ? `Connected for ${formatElapsedDurationLabel(lastConnectedAt, nowMs)}`
698 - : "Connected"
699 - : lastConnectedAt
700 - ? `Last connected at ${formatAccessTimestamp(lastConnectedAt)}`
701 - : "Not connected yet.";
702 - const deviceInfoBits = [
703 - clientSession.client.deviceType !== "unknown"
704 - ? clientSession.client.deviceType[0]?.toUpperCase() + clientSession.client.deviceType.slice(1)
705 - : null,
706 - clientSession.client.os ?? null,
707 - clientSession.client.browser ?? null,
708 - clientSession.client.ipAddress ?? null,
709 - ].filter((value): value is string => value !== null);
710 - const primaryLabel =
711 - clientSession.client.label ??
712 - ([clientSession.client.os, clientSession.client.browser].filter(Boolean).join(" · ") ||
713 - clientSession.subject);
714 -
715 - return (
716 - <div className={accessRowClassName(presentation)}>
717 - <div className={ITEM_ROW_INNER_CLASSNAME}>
718 - <div className="min-w-0 flex-1 space-y-1">
719 - <div className="flex min-h-5 items-center gap-1.5">
720 - <ConnectionStatusDot
721 - tooltipText={statusTooltip}
722 - dotClassName={isLive ? "bg-success" : "bg-muted-foreground/30"}
723 - pingClassName={isLive ? "bg-success/60 duration-2000" : null}
724 - />
725 - <h3 className="text-sm font-medium text-foreground">{primaryLabel}</h3>
726 - {clientSession.current ? (
727 - <span className="text-3xs text-muted-foreground/80 rounded-md border border-border/50 bg-muted/50 px-1 py-0.5">
728 - This device
729 - </span>
730 - ) : null}
731 - </div>
732 - <p className="text-xs text-muted-foreground">
733 - {deviceInfoBits.length > 0 ? (
734 - <>
735 - {deviceInfoBits.join(" · ")}
736 - <span aria-hidden> · </span>
737 - </>
738 - ) : null}
739 - <AccessScopeSummary scopes={clientSession.scopes} label="Client scopes" />
740 - </p>
741 - </div>
742 - <div className="flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end">
743 - {!clientSession.current ? (
744 - <Button
745 - size="xs"
746 - variant="destructive-outline"
747 - disabled={!canRevoke || revokingClientSessionId === clientSession.sessionId}
748 - onClick={() => void onRevokeSession(clientSession.sessionId)}
749 - >
750 - {revokingClientSessionId === clientSession.sessionId ? "Revoking…" : "Revoke"}
751 - </Button>
752 - ) : null}
753 - </div>
754 - </div>
755 - </div>
756 - );
757 -});
758 -
759 -type AuthorizedClientsHeaderActionProps = {
760 - onPairingLinkCreated: (result: AuthPairingCredentialResult) => void;
761 - clientSessions: ReadonlyArray<ServerClientSessionRecord> | null;
762 - isRevokingOtherClients: boolean;
763 - onRevokeOtherClients: () => void;
764 - delegatableScopes: ReadonlyArray<AuthEnvironmentScope>;
765 -};
766 -
767 -const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHeaderAction({
768 - onPairingLinkCreated,
769 - clientSessions,
770 - isRevokingOtherClients,
771 - onRevokeOtherClients,
772 - delegatableScopes,
773 -}: AuthorizedClientsHeaderActionProps) {
774 - const primaryEnvironmentId = usePrimaryEnvironmentId();
775 - const [dialogOpen, setDialogOpen] = useState(false);
776 - const [pairingLabel, setPairingLabel] = useState("");
777 - const [pairingScopes, setPairingScopes] = useState<ReadonlyArray<AuthGrantScope>>([
778 - ...AuthStandardClientScopes,
779 - ]);
780 - const selectedScopes = pairingScopes.filter((scope) => delegatableScopes.includes(scope));
781 - const [isCreatingPairingLink, setIsCreatingPairingLink] = useState(false);
782 -
783 - const handleCreatePairingLink = async () => {
784 - if (
785 - primaryEnvironmentId === null ||
786 - selectedScopes.length === 0 ||
787 - !readEnvironmentScope(primaryEnvironmentId, AuthAccessWriteScope) ||
788 - !selectedScopes.every((scope) => readEnvironmentScope(primaryEnvironmentId, scope))
789 - )
790 - return;
791 - setIsCreatingPairingLink(true);
792 - const settled = await settlePromise(async () => {
793 - const created = await createServerPairingCredential({
794 - label: pairingLabel,
795 - scopes: selectedScopes,
796 - });
797 - onPairingLinkCreated(created);
798 - setPairingLabel("");
799 - setPairingScopes(
800 - AuthStandardClientScopes.filter((scope) => delegatableScopes.includes(scope)),
801 - );
802 - setDialogOpen(false);
803 - });
804 - if (settled._tag === "Failure") {
805 - const error = Cause.squash(settled.cause);
806 - const message = error instanceof Error ? error.message : "Failed to create pairing URL.";
807 - toastManager.add(
808 - stackedThreadToast({
809 - type: "error",
810 - title: "Could not create pairing URL",
811 - description: message,
812 - }),
813 - );
814 - }
815 - setIsCreatingPairingLink(false);
816 - };
817 -
818 - const togglePairingScope = (scope: AuthGrantScope, checked: boolean) => {
819 - setPairingScopes((current) => togglePairingScopeSelection(current, scope, checked));
820 - };
821 -
822 - return (
823 - <div className="flex items-center gap-2">
824 - <Button
825 - size="xs"
826 - variant="destructive-outline"
827 - disabled={isRevokingOtherClients || !canRevokeOtherClients(clientSessions)}
828 - onClick={() => void onRevokeOtherClients()}
829 - >
830 - {isRevokingOtherClients ? "Revoking…" : "Revoke others"}
831 - </Button>
832 - <Dialog
833 - open={dialogOpen}
834 - onOpenChange={(open) => {
835 - setDialogOpen(open);
836 - if (!open) {
837 - setPairingLabel("");
838 - setPairingScopes(
839 - AuthStandardClientScopes.filter((scope) => delegatableScopes.includes(scope)),
840 - );
841 - }
842 - }}
843 - >
844 - <DialogTrigger
845 - render={
846 - <Button size="xs" variant="default">
847 - <PlusIcon className="size-3" />
848 - Create link
849 - </Button>
850 - }
851 - />
852 - <DialogPopup className="max-w-md">
853 - <DialogHeader>
854 - <DialogTitle>Create pairing link</DialogTitle>
855 - <DialogDescription>
856 - Generate a one-time link that another device can use to pair with this backend as an
857 - authorized client.
858 - </DialogDescription>
859 - </DialogHeader>
860 - <DialogPanel>
861 - <label className="block">
862 - <span className="mb-1.5 block text-xs font-medium text-foreground">
863 - Client label (optional)
864 - </span>
865 - <Input
866 - value={pairingLabel}
867 - onChange={(event) => setPairingLabel(event.target.value)}
868 - placeholder="e.g. Living room iPad"
869 - disabled={isCreatingPairingLink}
870 - autoFocus
871 - />
872 - </label>
873 - <section className="space-y-3">
874 - <div className="flex items-center justify-between gap-3">
875 - <div>
876 - <h3 className="text-xs font-medium text-foreground">Permissions</h3>
877 - <p className="text-xs text-muted-foreground">
878 - Limit what the paired client can do.
879 - </p>
880 - </div>
881 - <div className="flex gap-1">
882 - <Button
883 - size="xs"
884 - variant="outline"
885 - disabled={isCreatingPairingLink}
886 - onClick={() =>
887 - setPairingScopes(
888 - [
889 - AuthOrchestrationReadScope,
890 - AuthFilesystemReadScope,
891 - AuthDiagnosticsReadScope,
892 - AuthTerminalReadScope,
893 - ].filter((scope) => delegatableScopes.includes(scope)),
894 - )
895 - }
896 - >
897 - Read only
898 - </Button>
899 - <Button
900 - size="xs"
901 - variant="outline"
902 - disabled={isCreatingPairingLink}
903 - onClick={() =>
904 - setPairingScopes(
905 - AuthStandardClientScopes.filter((scope) =>
906 - delegatableScopes.includes(scope),
907 - ),
908 - )
909 - }
910 - >
911 - Standard
912 - </Button>
913 - </div>
914 - </div>
915 - <div className="divide-y divide-border/60 rounded-lg border border-input bg-muted/25">
916 - {PAIRING_SCOPE_OPTIONS.filter(({ scope }) => delegatableScopes.includes(scope)).map(
917 - ({ scope, title, description }) => (
918 - <label
919 - key={scope}
920 - className="flex cursor-pointer items-start gap-3 px-3 py-2.5 transition-colors hover:bg-muted/40"
921 - >
922 - <Checkbox
923 - className="mt-0.5"
924 - checked={pairingScopes.includes(scope)}
925 - disabled={isCreatingPairingLink}
926 - onCheckedChange={(checked) => togglePairingScope(scope, checked === true)}
927 - />
928 - <span className="min-w-0">
929 - <span className="block text-xs font-medium text-foreground">{title}</span>
930 - <span className="block text-xs leading-snug text-muted-foreground">
931 - {description}
932 - </span>
933 - </span>
934 - </label>
935 - ),
936 - )}
937 - </div>
938 - {selectedScopes.length === 0 ? (
939 - <p className="text-xs text-destructive">Select at least one permission.</p>
940 - ) : selectedScopes.includes(AuthAccessWriteScope) ? (
941 - <p className="text-xs text-warning">
942 - This client can create or revoke access for other devices.
943 - </p>
944 - ) : null}
945 - </section>
946 - </DialogPanel>
947 - <DialogFooter variant="bare">
948 - <Button
949 - variant="outline"
950 - disabled={isCreatingPairingLink}
951 - onClick={() => setDialogOpen(false)}
952 - >
953 - Cancel
954 - </Button>
955 - <Button
956 - disabled={isCreatingPairingLink || selectedScopes.length === 0}
957 - onClick={() => void handleCreatePairingLink()}
958 - >
959 - {isCreatingPairingLink ? "Creating…" : "Create link"}
960 - </Button>
961 - </DialogFooter>
962 - </DialogPopup>
963 - </Dialog>
964 - </div>
965 - );
966 -});
967 -
968 -type PairingClientsListProps = {
969 - endpointUrl: string | null | undefined;
970 - endpoints: ReadonlyArray<AdvertisedEndpoint>;
971 - defaultEndpointKey: string | null;
972 - presentation?: AccessSectionPresentation;
973 - isLoading: boolean;
974 - pairingLinks: ReadonlyArray<ServerPairingLinkRecord>;
975 - createdPairingCredentials: ReadonlyMap<string, string>;
976 - clientSessions: ReadonlyArray<ServerClientSessionRecord>;
977 - revokingPairingLinkId: string | null;
978 - revokingClientSessionId: string | null;
979 - onRevokePairingLink: (id: string) => void;
980 - onRevokeClientSession: (sessionId: ServerClientSessionRecord["sessionId"]) => void;
981 - canRevoke: boolean;
982 -};
983 -
984 -const PairingClientsList = memo(function PairingClientsList({
985 - endpointUrl,
986 - endpoints,
987 - defaultEndpointKey,
988 - presentation = "current",
989 - isLoading,
990 - pairingLinks,
991 - createdPairingCredentials,
992 - clientSessions,
993 - revokingPairingLinkId,
994 - revokingClientSessionId,
995 - onRevokePairingLink,
996 - onRevokeClientSession,
997 - canRevoke,
998 -}: PairingClientsListProps) {
999 - return (
1000 - <>
1001 - {pairingLinks.map((pairingLink) => (
1002 - <PairingLinkListRow
1003 - key={pairingLink.id}
1004 - pairingLink={pairingLink}
1005 - credential={createdPairingCredentials.get(pairingLink.id)}
1006 - endpointUrl={endpointUrl}
1007 - endpoints={endpoints}
1008 - defaultEndpointKey={defaultEndpointKey}
1009 - presentation={presentation}
1010 - revokingPairingLinkId={revokingPairingLinkId}
1011 - onRevoke={onRevokePairingLink}
1012 - canRevoke={canRevoke}
1013 - />
1014 - ))}
1015 -
1016 - {clientSessions.map((clientSession) => (
1017 - <ConnectedClientListRow
1018 - key={clientSession.sessionId}
1019 - clientSession={clientSession}
1020 - presentation={presentation}
1021 - revokingClientSessionId={revokingClientSessionId}
1022 - onRevokeSession={onRevokeClientSession}
1023 - canRevoke={canRevoke}
1024 - />
1025 - ))}
1026 -
1027 - {pairingLinks.length === 0 && clientSessions.length === 0 && !isLoading ? (
1028 - <div className={accessRowClassName(presentation)}>
1029 - <p className="text-xs text-muted-foreground/60">No pairing links or client sessions.</p>
1030 - </div>
1031 - ) : null}
1032 - </>
1033 - );
1034 -});
1035 -
1036 -type AdvertisedEndpointListRowProps = {
1037 - endpoint: AdvertisedEndpoint;
1038 - isDefault: boolean;
1039 - presentation?: AccessSectionPresentation;
1040 - onSetDefault: (endpoint: AdvertisedEndpoint) => void;
1041 - onSetupTailscaleServe: (endpoint: AdvertisedEndpoint) => void;
1042 - onDisableTailscaleServe: (endpoint: AdvertisedEndpoint) => void;
1043 - isUpdatingTailscaleServe: boolean;
1044 -};
1045 -
1046 -const AdvertisedEndpointListRow = memo(function AdvertisedEndpointListRow({
1047 - endpoint,
1048 - isDefault,
1049 - presentation = "current",
1050 - onSetDefault,
1051 - onSetupTailscaleServe,
1052 - onDisableTailscaleServe,
1053 - isUpdatingTailscaleServe,
1054 -}: AdvertisedEndpointListRowProps) {
1055 - const isAvailable = endpoint.status === "available";
1056 - const needsTailscaleSetup = isTailscaleHttpsEndpoint(endpoint) && endpoint.status !== "available";
1057 - const canDisableTailscaleServe =
1058 - isTailscaleHttpsEndpoint(endpoint) && endpoint.status === "available";
1059 - const shouldShowEndpointUrl = !needsTailscaleSetup;
1060 - const isEndpointRail = presentation === "endpoint-rail";
1061 - return (
1062 - <div className={endpointRowClassName(presentation, isAvailable)}>
1063 - {isEndpointRail && isDefault ? (
1064 - <span className="absolute inset-y-2 left-0 w-1 rounded-r-full bg-primary" aria-hidden />
1065 - ) : null}
1066 - <div className="flex min-h-6 min-w-0 flex-col gap-2 sm:-my-0.5 sm:flex-row sm:items-center">
1067 - <div className="flex min-w-0 items-baseline gap-3">
1068 - <h3 className="shrink-0 text-sm leading-5 font-medium text-foreground">
1069 - {endpoint.label}
1070 - </h3>
1071 - {shouldShowEndpointUrl ? (
1072 - <Tooltip>
1073 - <TooltipTrigger
1074 - render={
1075 - <p className="min-w-0 truncate text-xs leading-5 text-muted-foreground">
1076 - {endpoint.httpBaseUrl}
1077 - </p>
1078 - }
1079 - />
1080 - <TooltipPopup side="top">{endpoint.httpBaseUrl}</TooltipPopup>
1081 - </Tooltip>
1082 - ) : null}
1083 - {!isAvailable ? (
1084 - <span className="shrink-0 rounded-md border border-border/70 px-1 py-0.5 text-3xs text-muted-foreground">
1085 - Setup required
1086 - </span>
1087 - ) : null}
1088 - </div>
1089 - <div className="ml-auto flex min-h-6 shrink-0 items-center justify-end gap-2">
1090 - {isDefault ? (
1091 - <span className="rounded-md border border-primary/30 bg-primary/10 px-1 py-0.5 text-3xs text-primary">
1092 - Default
1093 - </span>
1094 - ) : null}
1095 - {needsTailscaleSetup ? (
1096 - <Button
1097 - size="xs"
1098 - variant="outline"
1099 - onClick={() => onSetupTailscaleServe(endpoint)}
1100 - disabled={isUpdatingTailscaleServe}
1101 - >
1102 - {isUpdatingTailscaleServe ? "Restarting…" : "Setup"}
1103 - </Button>
1104 - ) : null}
1105 - {canDisableTailscaleServe ? (
1106 - <Button
1107 - size="xs"
1108 - variant="destructive-outline"
1109 - onClick={() => onDisableTailscaleServe(endpoint)}
1110 - disabled={isUpdatingTailscaleServe}
1111 - >
1112 - {isUpdatingTailscaleServe ? "Restarting…" : "Disable"}
1113 - </Button>
1114 - ) : null}
1115 - {!needsTailscaleSetup && !isDefault ? (
1116 - <Button size="xs" variant="outline" onClick={() => onSetDefault(endpoint)}>
1117 - Set as default
1118 - </Button>
1119 - ) : null}
1120 - </div>
1121 - </div>
1122 - </div>
1123 - );
1124 -});
1125 -
1126 -function NetworkAccessDescription({
1127 - endpoint,
1128 - hiddenEndpointCount,
1129 - expanded,
1130 - onToggleExpanded,
1131 - fallback,
1132 -}: {
1133 - endpoint: AdvertisedEndpoint | null;
1134 - hiddenEndpointCount: number;
1135 - expanded: boolean;
1136 - onToggleExpanded: () => void;
1137 - fallback: ReactNode;
1138 -}) {
1139 - if (!endpoint) {
1140 - return fallback;
1141 - }
1142 -
1143 - const summary = (
1144 - <>
1145 - <span className="min-w-0 truncate">{endpoint.httpBaseUrl}</span>
1146 - {hiddenEndpointCount > 0 ? (
1147 - <span className="shrink-0 text-xs font-medium">
1148 - {expanded ? "Hide" : `+${hiddenEndpointCount}`}
1149 - </span>
1150 - ) : null}
1151 - </>
1152 - );
1153 -
1154 - return (
1155 - <span className="inline-flex min-w-0 max-w-full items-baseline gap-1">
1156 - <span className="shrink-0">Reachable at</span>
1157 - {hiddenEndpointCount > 0 ? (
1158 - <button
1159 - type="button"
1160 - className="inline-flex min-w-0 max-w-full items-baseline gap-2 border-b border-dotted border-muted-foreground/60 text-left text-muted-foreground underline-offset-4 hover:border-foreground hover:text-foreground"
1161 - onClick={onToggleExpanded}
1162 - aria-expanded={expanded}
1163 - >
1164 - {summary}
1165 - </button>
1166 - ) : (
1167 - <span className="inline-flex min-w-0 max-w-full items-baseline gap-2">{summary}</span>
1168 - )}
1169 - </span>
1170 - );
1171 -}
1172 -
220 type SavedBackendListRowProps = {
221 environment: EnvironmentPresentation;
222 removingEnvironmentId: EnvironmentId | null;
vite.config.ts
+1
@@ -284,6 +284,7 @@ export default defineConfig({
284 },
285 {
286 files: [
287 + "apps/web/src/components/settings/AuthorizedClientsSettings.tsx",
288 "apps/web/src/components/settings/ConnectionsSettings.tsx",
289 "apps/mobile/src/features/updates/app-updates.ts",
290 "apps/web/src/components/device/DevicePhoneViewport.tsx",