Skip to content

Commit 22c2e7a

Browse files
author
Saffron Normal Worker
committed
fix: unify fetch calls to use authedFetch for protected routes
Replace plain fetch() with authedFetch() in all client-side API calls to protected mutating and data routes. This ensures DISPATCH_AUTH_MODE=basic operators get consistent Basic Auth header injection. Files changed: - src/app/automation/activity/page.tsx: events list fetch - src/app/automation/workflows/[id]/page.tsx: workflow detail, dispatch, rerun - src/app/agents/agent-work-panel.tsx: agent work panel CRUD operations Left unchanged: login page session check (pre-auth, not a protected route) Fixes #319
1 parent 0a98c98 commit 22c2e7a

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/app/agents/agent-work-panel.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import { authedFetch } from "@/lib/client-auth";
34
import { useState, useEffect, useCallback } from "react";
45
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
56
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
@@ -75,7 +76,7 @@ export default function AgentWorkPanel() {
7576

7677
const fetchData = useCallback(async () => {
7778
try {
78-
const res = await fetch(`/api/agent-work?include_stale=true`);
79+
const res = await authedFetch(`/api/agent-work?include_stale=true`);
7980
if (res.ok) {
8081
const json: AgentWorkResponse = await res.json();
8182
setData(json);
@@ -94,7 +95,7 @@ export default function AgentWorkPanel() {
9495

9596
const handleRelease = async (workId: string | null, leaseId?: string) => {
9697
try {
97-
const res = await fetch("/api/agent-work", {
98+
const res = await authedFetch("/api/agent-work", {
9899
method: "POST",
99100
headers: { "Content-Type": "application/json" },
100101
body: JSON.stringify({ action: "release", workId, leaseId, reason: "Released by operator" }),
@@ -112,7 +113,7 @@ export default function AgentWorkPanel() {
112113
if (!newAgent?.trim()) return;
113114
setReassigning(workId);
114115
try {
115-
const res = await fetch("/api/agent-work", {
116+
const res = await authedFetch("/api/agent-work", {
116117
method: "POST",
117118
headers: { "Content-Type": "application/json" },
118119
body: JSON.stringify({ action: "reassign", workId, newAgentName: newAgent.trim(), reason: "Reassigned by operator" }),

src/app/automation/activity/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import { authedFetch } from "@/lib/client-auth";
34
import { useEffect, useState } from "react";
45
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
56
import { Badge } from "@/components/ui/badge";
@@ -47,7 +48,7 @@ export default function ActivityFeedPage() {
4748
const [loading, setLoading] = useState(true);
4849

4950
useEffect(() => {
50-
fetch("/api/automation/events?limit=100")
51+
authedFetch("/api/automation/events?limit=100")
5152
.then((res) => res.json())
5253
.then((data) => setEvents(data))
5354
.catch(() => setEvents([]))

src/app/automation/workflows/[id]/page.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import { authedFetch } from "@/lib/client-auth";
34
import { useEffect, useState, use } from "react";
45
import Link from "next/link";
56
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
@@ -83,7 +84,7 @@ export default function WorkflowDetailPage({ params }: { params: Promise<{ id: s
8384

8485
useEffect(() => {
8586
if (!workflowId) return;
86-
fetch(`/api/automation/workflows/${workflowId}`)
87+
authedFetch(`/api/automation/workflows/${workflowId}`)
8788
.then((res) => {
8889
if (!res.ok) throw new Error("Workflow not found");
8990
return res.json();
@@ -134,7 +135,7 @@ export default function WorkflowDetailPage({ params }: { params: Promise<{ id: s
134135
variant="outline"
135136
onClick={() => {
136137
if (workflow.runs[0]) {
137-
fetch(`/api/automation/runs/${workflow.runs[0].runId}?repo=${workflow.repo.fullName}&action=dispatch`, { method: "POST" })
138+
authedFetch(`/api/automation/runs/${workflow.runs[0].runId}?repo=${workflow.repo.fullName}&action=dispatch`, { method: "POST" })
138139
.then(() => window.location.reload());
139140
}
140141
}}
@@ -230,7 +231,7 @@ export default function WorkflowDetailPage({ params }: { params: Promise<{ id: s
230231
variant="ghost"
231232
size="sm"
232233
onClick={() => {
233-
fetch(`/api/automation/runs/${run.runId}?repo=${workflow.repo.fullName}&action=rerun`, { method: "POST" })
234+
authedFetch(`/api/automation/runs/${run.runId}?repo=${workflow.repo.fullName}&action=rerun`, { method: "POST" })
234235
.then(() => window.location.reload());
235236
}}
236237
>

0 commit comments

Comments
 (0)