fix(cli): sidebar delete conversation — fix silent failure
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful

Add missing Origin header to all requests in use-conversations hook.
BetterAuth requires Origin for session validation; without it DELETE
requests return 401 which was silently swallowed, causing 'd' in the
sidebar to appear as a no-op. Fixes #191.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-16 21:34:04 -05:00
parent 7a52652be6
commit 048bc14a2c

View File

@@ -31,18 +31,22 @@ export function useConversations(opts: UseConversationsOptions): UseConversation
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const mountedRef = useRef(true); const mountedRef = useRef(true);
const headers = useCallback((): Record<string, string> => { const headers = useCallback(
const h: Record<string, string> = { 'Content-Type': 'application/json' }; (includeContentType = true): Record<string, string> => {
const h: Record<string, string> = { Origin: gatewayUrl };
if (includeContentType) h['Content-Type'] = 'application/json';
if (sessionCookie) h['Cookie'] = sessionCookie; if (sessionCookie) h['Cookie'] = sessionCookie;
return h; return h;
}, [sessionCookie]); },
[gatewayUrl, sessionCookie],
);
const refresh = useCallback(async () => { const refresh = useCallback(async () => {
if (!mountedRef.current) return; if (!mountedRef.current) return;
setLoading(true); setLoading(true);
setError(null); setError(null);
try { try {
const res = await fetch(`${gatewayUrl}/api/conversations`, { headers: headers() }); const res = await fetch(`${gatewayUrl}/api/conversations`, { headers: headers(false) });
if (!res.ok) throw new Error(`HTTP ${res.status}`); if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = (await res.json()) as ConversationSummary[]; const data = (await res.json()) as ConversationSummary[];
if (mountedRef.current) { if (mountedRef.current) {
@@ -93,7 +97,7 @@ export function useConversations(opts: UseConversationsOptions): UseConversation
try { try {
const res = await fetch(`${gatewayUrl}/api/conversations/${id}`, { const res = await fetch(`${gatewayUrl}/api/conversations/${id}`, {
method: 'DELETE', method: 'DELETE',
headers: headers(), headers: headers(false),
}); });
if (!res.ok) return false; if (!res.ok) return false;
if (mountedRef.current) { if (mountedRef.current) {