fix: use native fetch with credentials for remote dashboard

This commit is contained in:
OpenCode Agent 2026-08-17 15:23:40 +00:00
parent 11987a8311
commit 18628e9e36
1 changed files with 25 additions and 4 deletions

View File

@ -5,7 +5,28 @@
const { React } = SDK; const { React } = SDK;
const { useState, useEffect, useCallback } = SDK.hooks; const { useState, useEffect, useCallback } = SDK.hooks;
const { Card, CardHeader, CardTitle, CardContent, Button } = SDK.components; const { Card, CardHeader, CardTitle, CardContent, Button } = SDK.components;
const fetchJSON = SDK.fetchJSON;
// Use native fetch with credentials for remote dashboard
async function apiFetch(path) {
const res = await fetch(path, { credentials: "include" });
if (!res.ok) {
const text = await res.text();
throw new Error("API error " + res.status + ": " + text.slice(0, 100));
}
return res.json();
}
async function apiPost(path) {
const res = await fetch(path, {
method: "POST",
credentials: "include"
});
if (!res.ok) {
const text = await res.text();
throw new Error("API error " + res.status + ": " + text.slice(0, 100));
}
return res.json();
}
function SSHXPage() { function SSHXPage() {
const [link, setLink] = useState(null); const [link, setLink] = useState(null);
@ -16,7 +37,7 @@
setStatus("loading"); setStatus("loading");
setError(null); setError(null);
try { try {
const res = await fetchJSON("/api/plugins/sshx-link/start"); const res = await apiFetch("/api/plugins/sshx-link/start");
if (res.link) { if (res.link) {
setLink(res.link); setLink(res.link);
setStatus("running"); setStatus("running");
@ -32,7 +53,7 @@
const stopSSHX = useCallback(async function () { const stopSSHX = useCallback(async function () {
try { try {
await fetchJSON("/api/plugins/sshx-link/stop"); await apiPost("/api/plugins/sshx-link/stop");
setLink(null); setLink(null);
setStatus("idle"); setStatus("idle");
} catch (err) { } catch (err) {
@ -42,7 +63,7 @@
const checkStatus = useCallback(async function () { const checkStatus = useCallback(async function () {
try { try {
const res = await fetchJSON("/api/plugins/sshx-link/status"); const res = await apiFetch("/api/plugins/sshx-link/status");
if (res.status === "running" && res.link) { if (res.status === "running" && res.link) {
setLink(res.link); setLink(res.link);
setStatus("running"); setStatus("running");