/** * @file useCcTarget — whose Claude Code config the Config Explorer manages for * this login (GET /api/cc-config/target). Local mode and an admin: the host's, * answered at once without a request (nothing changes for them). A non-admin * in server mode asks the server: `own` when they have their own Linux account * (S3) — Settings then shows "Your Claude Code config" — else `none` and the * page stays hidden. The server's refusal (403 ENOACCOUNT/EADMIN) is the rule; * this only hides what would be refused. * @author Nguyễn Ngọc Trí Vĩ */ import { useEffect, useState } from "react"; import { api, type CcTarget } from "../lib/api"; import { usePermissions } from "../components/AuthGate"; const HOST: CcTarget = { kind: "host", readOnly: false, claudeHome: null }; /** `null` while a non-admin's answer is on its way. */ export function useCcTarget(): CcTarget | null { const { isAdmin } = usePermissions(); const [target, setTarget] = useState(isAdmin ? HOST : null); useEffect(() => { if (isAdmin) { setTarget(HOST); return; } let live = true; api.ccConfig .target() .then((t) => { if (live) setTarget(t); }) .catch(() => { if (live) setTarget({ kind: "none", readOnly: true, claudeHome: null }); }); return () => { live = false; }; }, [isAdmin]); return target; }