diff --git a/js/api.js b/js/api.js index b56fed8..ad6711a 100644 --- a/js/api.js +++ b/js/api.js @@ -901,7 +901,17 @@ async function apiFetch(path, options = {}) { const token = getToken(); const headers = { 'Content-Type': 'application/json', ...(options.headers || {}) }; if (token) headers['Authorization'] = `Bearer ${token}`; - const res = await fetch(path, { ...options, headers }); + // Auto-stringify plain object bodies so callers can pass `{ body: { ... } }` + // like LS.post does. Strings / FormData / Blob / URLSearchParams pass through. + const opts = { ...options, headers }; + if (opts.body && typeof opts.body === 'object' + && !(opts.body instanceof FormData) + && !(opts.body instanceof Blob) + && !(opts.body instanceof URLSearchParams) + && !(opts.body instanceof ArrayBuffer)) { + opts.body = JSON.stringify(opts.body); + } + const res = await fetch(path, opts); if (res.status === 401) { removeToken(); removeUser(); window.location.href = '/login';