import { useMemo } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { Link, useParams, useSearchParams } from "@/lib/router"; import { Button } from "@/components/ui/button"; import { accessApi } from "../api/access"; import { authApi } from "../api/auth"; import { queryKeys } from "../lib/queryKeys"; export function CliAuthPage() { const queryClient = useQueryClient(); const params = useParams(); const [searchParams] = useSearchParams(); const challengeId = (params.id ?? "").trim(); const token = (searchParams.get("token") ?? "").trim(); const currentPath = useMemo( () => `/cli-auth/${encodeURIComponent(challengeId)}${token ? `?token=${encodeURIComponent(token)}` : ""}`, [challengeId, token], ); const sessionQuery = useQuery({ queryKey: queryKeys.auth.session, queryFn: () => authApi.getSession(), retry: false, }); const challengeQuery = useQuery({ queryKey: ["cli-auth-challenge", challengeId, token], queryFn: () => accessApi.getCliAuthChallenge(challengeId, token), enabled: challengeId.length > 0 && token.length > 0, retry: false, }); const approveMutation = useMutation({ mutationFn: () => accessApi.approveCliAuthChallenge(challengeId, token), onSuccess: async () => { await queryClient.invalidateQueries({ queryKey: queryKeys.auth.session }); await challengeQuery.refetch(); }, }); const cancelMutation = useMutation({ mutationFn: () => accessApi.cancelCliAuthChallenge(challengeId, token), onSuccess: async () => { await challengeQuery.refetch(); }, }); if (!challengeId || !token) { return
{challengeQuery.error instanceof Error ? challengeQuery.error.message : "Challenge is invalid or expired."}
The Paperclip CLI can now finish authentication on the requesting machine.
Command: {challenge.command}
Start the CLI auth flow again from your terminal to generate a new approval request.
Sign in or create an account, then return to this page to approve the CLI access request.
A local Paperclip CLI process is requesting board access to this instance.
{(approveMutation.error ?? cancelMutation.error) instanceof Error ? ((approveMutation.error ?? cancelMutation.error) as Error).message : "Failed to update CLI auth challenge"}
)} {!challenge.canApprove && (This challenge requires instance-admin access. Sign in with an instance admin account to approve it.
)}