fix(web-admin): use apiClient for openclaw-instances to forward JWT

Bare fetch() was not sending Authorization header, causing 401.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-03-08 01:06:28 -08:00
parent c33c45d474
commit ece778e593
1 changed files with 5 additions and 14 deletions

View File

@ -4,6 +4,7 @@ import { useState } from 'react';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { toast } from 'sonner';
import { RefreshCw, Boxes, CheckCircle, AlertCircle, Clock, XCircle, StopCircle } from 'lucide-react';
import { apiClient } from '@/infrastructure/api/api-client';
interface AgentInstance {
id: string;
@ -22,28 +23,18 @@ interface AgentInstance {
updatedAt: string;
}
const API = '/api/proxy/api/v1/agent/instances';
const API_PATH = '/api/v1/agent/instances';
async function fetchInstances(): Promise<AgentInstance[]> {
const res = await fetch(API);
if (!res.ok) throw new Error('Failed to load instances');
return res.json();
return apiClient<AgentInstance[]>(API_PATH);
}
async function stopInstance(id: string): Promise<void> {
const res = await fetch(`${API}/${id}/stop`, { method: 'PUT' });
if (!res.ok) {
const err = await res.json().catch(() => ({}));
throw new Error((err as any).message ?? 'Failed to stop instance');
}
await apiClient(`${API_PATH}/${id}/stop`, { method: 'PUT' });
}
async function removeInstance(id: string): Promise<void> {
const res = await fetch(`${API}/${id}`, { method: 'DELETE' });
if (!res.ok) {
const err = await res.json().catch(() => ({}));
throw new Error((err as any).message ?? 'Failed to remove instance');
}
await apiClient(`${API_PATH}/${id}`, { method: 'DELETE' });
}
const STATUS_CONFIG = {