mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-14 13:22:37 +00:00
* feat(auth): authenticate daemon clients through hello Give local CLI and desktop clients a per-run credential while remote clients send the host password inside the protocol. Keep relay passwordless admission for this mobile release so existing saved hosts keep working until the follow-up enforcement release. Move password recovery for saved hosts into host settings and keep pairing credentials in the add flow. Include isolated web QA evidence for both flows. * fix(auth): preserve Hub bootstrap and local credential expectations Hub-owned sockets already carry admission; keep their hello handling synchronous through session bootstrap while resolving credentials asynchronously for ordinary sockets. Keep the resolver out of lightweight configuration imports. Update CLI expectations for same-home credentials, let a rejected connection yield to another usable connection, and clear pairing secrets when add-flow targets change. * fix(pairing): retain passwords across edits to the same target Track the last valid pairing host while a URI is edited. This preserves an entered password for whitespace and partial edits but clears it when a different host becomes the target. * test(auth): align local credential checks across platforms Expect the CLI to authenticate through the credential in its selected home, and verify POSIX file modes only where Node exposes them. * feat(app): move host password into a settings row with a modal The host page rendered an always-visible password form above Name on every host. Replace it with a Password row under a Security section below Appearance; tapping it opens a modal with Save and, when a password is saved, Clear. The connection-error callout keeps its guidance and gains a Set password button that opens the same modal. Drop the unused pairing.hostPassword body/reopen/saveError strings. * chore: remove committed QA screenshots QA evidence stays out of the repository; the PR body describes it in words. * feat(app): keep the host password out of the host page The saved password is connection data, entered only when a host is added. A Password setting on the host page reads as the daemon's own password, so the row, modal, and callout button are gone. A rejected host shows the daemon's reason with guidance to remove the host and add it again with the password. useHostMutations no longer exposes setHostPassword; relay imports still set it inside the runtime. * feat(app): show host connection errors in an error alert HostConnectionError renders the existing Alert with the connection error as its title. Auth rejections add the re-add guidance as the description; other errors show the title only. The Overview and Connections pages share it. * style(app): soften alert borders to half-opacity accent * feat(app): size alerts on the button scale Alert takes a size prop (xs/sm/md/lg, default md) whose geometry lives next to the button's in control-geometry: one font size for title and description, the button icon size centered on the first text line, button padding and radius, and a one-line alert as tall as the button of the same size. Consumers pick sm among settings rows, cards, panels, and modals, and md when the alert is the whole page or sheet state. * style(app): roomier, rounder alerts with a tight title block Alert sm padding returns to the original 12/16 and every size is at least borderRadius.xl. Title and description sit a small gap apart with no line height override. The icon slot carries a zero-width text strut in the alert's font so the icon centers on the first line for titled, title-only, and description-only alerts. * refactor(app): align the alert icon with a centered lead row Drop the zero-width strut. The icon and the alert's first text (title, else description) share one row centered on each other; the description and actions sit below, indented by the icon slot width plus gap so they start at the lead text's left edge. * refactor(app): drop the unused Alert icon override
288 lines
8.6 KiB
TypeScript
288 lines
8.6 KiB
TypeScript
import { useCallback, useMemo, useReducer, useRef, useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Alert, Text, View } from "react-native";
|
|
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
|
import { useIsCompactFormFactor } from "@/constants/layout";
|
|
import { Link } from "lucide-react-native";
|
|
import type { HostProfile } from "@/types/host-connection";
|
|
import { useHosts, useHostMutations } from "@/runtime/host-runtime";
|
|
import { parseRelayConnectionUri } from "@/utils/daemon-endpoints";
|
|
import { parseConnectionOfferFromUrl } from "@getpaseo/protocol/connection-offer";
|
|
import { AdaptiveModalSheet, AdaptiveTextInput, type SheetHeader } from "./adaptive-modal-sheet";
|
|
import { getConnectionAuthFailureReason } from "@/utils/test-daemon-connection";
|
|
import { PairingTargetTracker } from "./pair-link-credentials";
|
|
import { Button } from "@/components/ui/button";
|
|
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
|
|
|
const FLEX_ONE_STYLE = { flex: 1 } as const;
|
|
|
|
function parsedHostLabel(input: string): string {
|
|
try {
|
|
if (input.startsWith("relay://") || input.includes("#connect=")) {
|
|
return parseRelayConnectionUri(input).offer.serverId;
|
|
}
|
|
return parseConnectionOfferFromUrl(input)?.serverId ?? "host";
|
|
} catch {
|
|
return "host";
|
|
}
|
|
}
|
|
|
|
const styles = StyleSheet.create((theme) => ({
|
|
helper: {
|
|
color: theme.colors.foregroundMuted,
|
|
fontSize: theme.fontSize.base,
|
|
},
|
|
field: {
|
|
gap: theme.spacing[2],
|
|
},
|
|
label: {
|
|
color: theme.colors.foregroundMuted,
|
|
fontSize: theme.fontSize.base,
|
|
fontWeight: theme.fontWeight.medium,
|
|
},
|
|
input: {
|
|
backgroundColor: theme.colors.surface2,
|
|
borderRadius: theme.borderRadius.lg,
|
|
paddingHorizontal: theme.spacing[4],
|
|
paddingVertical: theme.spacing[3],
|
|
color: theme.colors.foreground,
|
|
borderWidth: 1,
|
|
borderColor: theme.colors.border,
|
|
},
|
|
error: {
|
|
color: theme.colors.destructive,
|
|
fontSize: theme.fontSize.base,
|
|
},
|
|
actions: {
|
|
flexDirection: "row",
|
|
gap: theme.spacing[3],
|
|
marginTop: theme.spacing[2],
|
|
},
|
|
}));
|
|
|
|
export interface PairLinkModalProps {
|
|
visible: boolean;
|
|
initialUrl?: string;
|
|
initialPasswordRequired?: boolean;
|
|
onClose: () => void;
|
|
onCancel?: () => void;
|
|
onSaved?: (result: {
|
|
profile: HostProfile;
|
|
serverId: string;
|
|
hostname: string | null;
|
|
isNewHost: boolean;
|
|
}) => void;
|
|
}
|
|
|
|
export function PairLinkModal({
|
|
visible,
|
|
initialUrl,
|
|
initialPasswordRequired = false,
|
|
onClose,
|
|
onCancel,
|
|
onSaved,
|
|
}: PairLinkModalProps) {
|
|
return (
|
|
<PairLinkModalContent
|
|
key={`${visible}:${initialUrl ?? ""}:${initialPasswordRequired}`}
|
|
visible={visible}
|
|
initialUrl={initialUrl}
|
|
initialPasswordRequired={initialPasswordRequired}
|
|
onClose={onClose}
|
|
onCancel={onCancel}
|
|
onSaved={onSaved}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function PairLinkModalContent({
|
|
visible,
|
|
initialUrl,
|
|
initialPasswordRequired = false,
|
|
onClose,
|
|
onCancel,
|
|
onSaved,
|
|
}: PairLinkModalProps) {
|
|
const { theme } = useUnistyles();
|
|
const { t } = useTranslation();
|
|
const daemons = useHosts();
|
|
const { probeAndUpsertConnectionFromOfferUrl } = useHostMutations();
|
|
const isMobile = useIsCompactFormFactor();
|
|
|
|
const offerUrlRef = useRef(initialUrl ?? "");
|
|
const targetTracker = useRef(new PairingTargetTracker(initialUrl));
|
|
const inputRef = useRef<EditingTextInputHandle>(null);
|
|
const [isSaving, setIsSaving] = useState(false);
|
|
const [errorMessage, setErrorMessage] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
const [needsPassword, setNeedsPassword] = useState(initialPasswordRequired);
|
|
const [passwordResetKey, resetPasswordInput] = useReducer((key: number) => key + 1, 0);
|
|
|
|
const clearInput = useCallback(() => {
|
|
offerUrlRef.current = "";
|
|
targetTracker.current = new PairingTargetTracker();
|
|
inputRef.current?.replaceText("");
|
|
setPassword("");
|
|
setNeedsPassword(false);
|
|
resetPasswordInput();
|
|
}, []);
|
|
|
|
const pairIcon = useMemo(
|
|
() => <Link size={16} color={theme.colors.accentForeground} />,
|
|
[theme.colors.accentForeground],
|
|
);
|
|
|
|
const handleClose = useCallback(() => {
|
|
if (isSaving) return;
|
|
clearInput();
|
|
setErrorMessage("");
|
|
onClose();
|
|
}, [isSaving, clearInput, onClose]);
|
|
|
|
const handleCancel = useCallback(() => {
|
|
if (isSaving) return;
|
|
clearInput();
|
|
setErrorMessage("");
|
|
(onCancel ?? onClose)();
|
|
}, [isSaving, clearInput, onCancel, onClose]);
|
|
|
|
const handleSave = useCallback(
|
|
async (input?: string) => {
|
|
if (isSaving) return;
|
|
const raw = (input ?? offerUrlRef.current).trim();
|
|
if (!raw) {
|
|
setErrorMessage(t("pairing.link.errors.required"));
|
|
return;
|
|
}
|
|
if (!raw.includes("#offer=") && !raw.startsWith("relay://") && !raw.includes("#connect=")) {
|
|
setErrorMessage(t("pairing.link.errors.missingOffer"));
|
|
return;
|
|
}
|
|
|
|
try {
|
|
setIsSaving(true);
|
|
setErrorMessage("");
|
|
const { profile, serverId, hostname } = await probeAndUpsertConnectionFromOfferUrl(
|
|
raw,
|
|
password || undefined,
|
|
);
|
|
const isNewHost = !daemons.some((daemon) => daemon.serverId === serverId);
|
|
onSaved?.({ profile, serverId, hostname, isNewHost });
|
|
handleClose();
|
|
} catch (error) {
|
|
const message =
|
|
error instanceof Error ? error.message : t("pairing.link.errors.unableToPair");
|
|
setErrorMessage(message);
|
|
if (getConnectionAuthFailureReason(error)) {
|
|
setNeedsPassword(true);
|
|
return;
|
|
}
|
|
if (!isMobile) {
|
|
Alert.alert(t("pairing.link.alert.failedTitle"), message);
|
|
}
|
|
} finally {
|
|
setIsSaving(false);
|
|
}
|
|
},
|
|
[
|
|
daemons,
|
|
handleClose,
|
|
isMobile,
|
|
isSaving,
|
|
onSaved,
|
|
password,
|
|
t,
|
|
probeAndUpsertConnectionFromOfferUrl,
|
|
],
|
|
);
|
|
|
|
const handleChangeOfferUrl = useCallback((next: string) => {
|
|
if (targetTracker.current.changeUrl(next)) {
|
|
setPassword("");
|
|
setNeedsPassword(false);
|
|
resetPasswordInput();
|
|
setErrorMessage("");
|
|
}
|
|
offerUrlRef.current = next;
|
|
}, []);
|
|
|
|
const handleSavePress = useCallback(() => {
|
|
void handleSave();
|
|
}, [handleSave]);
|
|
|
|
const header = useMemo<SheetHeader>(() => ({ title: t("pairing.link.title") }), [t]);
|
|
|
|
return (
|
|
<AdaptiveModalSheet
|
|
header={header}
|
|
visible={visible}
|
|
onClose={handleClose}
|
|
testID="pair-link-modal"
|
|
>
|
|
<Text style={styles.helper}>{t("pairing.link.helper")}</Text>
|
|
|
|
<View style={styles.field}>
|
|
<Text style={styles.label}>{t("pairing.link.label")}</Text>
|
|
<AdaptiveTextInput
|
|
ref={inputRef}
|
|
initialValue={initialUrl}
|
|
testID="pair-link-input"
|
|
nativeID="pair-link-input"
|
|
accessibilityLabel={t("pairing.link.label")}
|
|
onChangeText={handleChangeOfferUrl}
|
|
placeholder="https://app.paseo.sh/#offer=..."
|
|
placeholderTextColor={theme.colors.foregroundMuted}
|
|
style={styles.input}
|
|
autoFocus
|
|
autoCapitalize="none"
|
|
autoCorrect={false}
|
|
keyboardType="url"
|
|
/>
|
|
{errorMessage ? <Text style={styles.error}>{errorMessage}</Text> : null}
|
|
</View>
|
|
|
|
{needsPassword ? (
|
|
<View style={styles.field}>
|
|
<Text style={styles.label}>
|
|
{t("pairing.hostPassword.title", { host: parsedHostLabel(offerUrlRef.current) })}
|
|
</Text>
|
|
<AdaptiveTextInput
|
|
testID="pair-link-password-input"
|
|
resetKey={`pair-link-password-${passwordResetKey}`}
|
|
accessibilityLabel={t("pairing.hostPassword.label")}
|
|
onChangeText={setPassword}
|
|
secureTextEntry
|
|
style={styles.input}
|
|
/>
|
|
</View>
|
|
) : null}
|
|
|
|
<View style={styles.actions}>
|
|
<Button
|
|
style={FLEX_ONE_STYLE}
|
|
variant="secondary"
|
|
onPress={handleCancel}
|
|
disabled={isSaving}
|
|
testID="pair-link-cancel"
|
|
accessibilityRole="button"
|
|
accessibilityLabel={t("pairing.link.actions.cancel")}
|
|
>
|
|
{t("pairing.link.actions.cancel")}
|
|
</Button>
|
|
<Button
|
|
style={FLEX_ONE_STYLE}
|
|
variant="default"
|
|
onPress={handleSavePress}
|
|
disabled={isSaving}
|
|
testID="pair-link-submit"
|
|
accessibilityRole="button"
|
|
accessibilityLabel={t("pairing.link.actions.pair")}
|
|
leftIcon={pairIcon}
|
|
>
|
|
{isSaving ? t("pairing.link.actions.pairing") : t("pairing.link.actions.pair")}
|
|
</Button>
|
|
</View>
|
|
</AdaptiveModalSheet>
|
|
);
|
|
}
|