MCPcopy
hub / github.com/dataelement/Clawith / fetchAuth

Function fetchAuth

frontend/src/components/ChannelConfig.tsx:8–23  ·  view source on GitHub ↗
(url: string, options?: RequestInit)

Source from the content-addressed store, hash-verified

6import LinearCopyButton from './LinearCopyButton';
7// ─── Shared fetchAuth (same as AgentDetail) ─────────────
8function fetchAuth<T>(url: string, options?: RequestInit): Promise<T> {
9 const token = localStorage.getItem('token');
10 return fetch(`/api${url}`, {
11 ...options,
12 headers: { 'Content-Type': 'application/json', ...(token ? { Authorization: `Bearer ${token}` } : {}) },
13 }).then(async r => {
14 if (r.status === 204) {
15 return undefined as T;
16 }
17 if (!r.ok) {
18 const error = await r.json().catch(() => ({ detail: `HTTP ${r.status}` }));
19 throw new Error(error.detail || `HTTP ${r.status}`);
20 }
21 return r.json() as Promise<T>;
22 });
23}
24
25// ─── Types ──────────────────────────────────────────────
26interface ChannelConfigProps {

Callers 1

ChannelConfigFunction · 0.70

Calls 1

jsonMethod · 0.45

Tested by

no test coverage detected