Let clients without a managed backend manage pairing #4496
Closedcolonelpanic8(GitHub profile, opens in a new tab)wants to merge 7 commits into
main fromrefs/pull/4496/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
- apps/web/src/components/settings/ConnectionsSettings.tsx line 983Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -972,3 +977,4 @@972977 clientSessions: ReadonlyArray<ServerClientSessionRecord>;973978 isRevokingOtherClients: boolean;974979 onRevokeOtherClients: () => void;980+ // Supplied by the parent so the link is minted on whichever environment the
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/web/src/components/settings/ConnectionsSettings.logic.ts line 91Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1,0 +49,21 @@49+ * server being administered.50+ *51+ * The page's own origin is only one of those addresses when this page is served52+ * by the administered server — the managed-backend case. For any other53+ * environment (a saved server reached over the network, a relay, or an SSH54+ * tunnel) an origin-relative link would pair the scanning device to this client55+ * app instead of the server the link belongs to, so there is no shareable URL56+ * and the caller falls back to showing the bare pairing code. A loopback origin57+ * is likewise unshareable: it resolves to the scanning device, not to us.58+ */59+export function resolveShareablePairingUrl(input: {60+ /** Pairing URL for the advertised endpoint the user picked, when there is one. */61+ readonly endpointPairingUrl: string | null;62+ /** Pairing URL built from the administered server's own base URL. */63+ readonly basePairingUrl: string | null;64+ /** Pairing URL on this page's origin. */65+ readonly currentOriginPairingUrl: string;66+ /** Whether the administered server is the one serving this page. */67+ readonly servesCurrentOrigin: boolean;68+ readonly isCurrentOriginLoopback: boolean;69+}): string | null {
- apps/web/src/components/settings/ConnectionsSettings.logic.ts line 56OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1,0 +36,21 @@36+ case "PrimaryConnectionTarget":37+ return entry.target.httpBaseUrl;38+ case "BearerConnectionTarget":39+ return Option.isSome(entry.profile) && entry.profile.value._tag === "BearerConnectionProfile"40+ ? entry.profile.value.httpBaseUrl41+ : null;42+ case "RelayConnectionTarget":43+ case "SshConnectionTarget":44+ return null;45+ }46+}47+48+function isLoopbackPairingUrl(value: string): boolean {49+ const pairingUrl = new URL(value);50+ if (isLoopbackHost(pairingUrl.hostname)) return true;51+52+ // Hosted app links wrap the administered server's address in `host`, so the53+ // outer URL can be public even when the target still resolves to the scanning54+ // device itself.55+ const targetUrl = pairingUrl.searchParams.get("host");56+ return targetUrl !== null && isLoopbackHost(new URL(targetUrl).hostname);
- apps/web/src/components/settings/ConnectionsSettings.tsx line 1909Resolvedby colonelpanic8(GitHub profile, opens in a new tab)@@ -1845,0 +1881,21 @@1881+ const accessEnvironment =1882+ accessEnvironmentId === null1883+ ? null1884+ : (environments.find(1885+ (environment) => environment.entry.target.environmentId === accessEnvironmentId,1886+ ) ?? null);1887+ // Scopes come from the session on the server being administered. For a1888+ // non-primary environment that is the credential this client paired with,1889+ // which is administrative when it was bootstrapped from the server's own1890+ // startup token and standard-only when it came from an ordinary pairing link.1891+ const accessEnvironmentSession = useEnvironmentQuery(1892+ !isAccessEnvironmentPrimary && accessEnvironmentId !== null1893+ ? authEnvironment.sessionState({ environmentId: accessEnvironmentId, input: null })1894+ : null,1895+ );1896+ const accessSessionScopes = isAccessEnvironmentPrimary1897+ ? currentSessionScopes1898+ : accessEnvironmentSession.data?.authenticated1899+ ? (accessEnvironmentSession.data.scopes ?? null)1900+ : null;1901+ const canManageEnvironmentAccess = accessSessionScopes?.includes(AuthAccessWriteScope) ?? false;
- apps/web/src/components/ChatView.tsx line 1138Resolvedby colonelpanic8(GitHub profile, opens in a new tab)@@ -1132,3 +1133,6 @@11321133 forceExpandedMobileComposer = false,11331134 } = props;11341135 const draftId = routeKind === "draft" ? props.draftId : null;1136+ useEffect(() => {1137+ setActiveEnvironmentId(environmentId);1138+ }, [environmentId]);
Sign in to join this conversation.







Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
8d9ca262-d93f-44c9-bee9-b4956186a9ccYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share