fix: add auth token to all API calls (prompts, insights, pipeline)
Some checks failed
Deploy to Raspberry Pi / deploy (push) Failing after 12s
Build Test / build-frontend (push) Failing after 2s
Build Test / lint-backend (push) Failing after 1s

This commit is contained in:
Lars Stommer 2026-03-16 16:52:36 +01:00
parent 89b6c0b072
commit 5091dfd1ce
5 changed files with 9 additions and 19 deletions

View File

@ -117,7 +117,7 @@ export default function Analysis() {
const loadAll = async () => {
const [p, i] = await Promise.all([
fetch('/api/prompts').then(r=>r.json()),
api.listPrompts(),
api.listInsights()
])
setPrompts(Array.isArray(p)?p:[])
@ -128,12 +128,7 @@ export default function Analysis() {
const runPipeline = async () => {
setPipelineLoading(true); setError(null); setNewResult(null)
try {
const pid = localStorage.getItem('bodytrack_active_profile')||''
const r = await fetch('/api/insights/pipeline', {
method:'POST', headers: pid ? {'X-Profile-Id':pid} : {}
})
if (!r.ok) throw new Error(await r.text())
const result = await r.json()
const result = await api.insightPipeline()
setNewResult(result)
await loadAll()
setTab('run')
@ -145,12 +140,7 @@ export default function Analysis() {
const runPrompt = async (slug) => {
setLoading(slug); setError(null); setNewResult(null)
try {
const pid = localStorage.getItem('bodytrack_active_profile')||''
const r = await fetch(`/api/insights/run/${slug}`, {
method:'POST', headers: pid ? {'X-Profile-Id':pid} : {}
})
if (!r.ok) throw new Error(await r.text())
const result = await r.json()
const result = await api.runInsight(slug)
setNewResult(result) // show immediately
await loadAll() // refresh lists
setTab('run') // stay on run tab to see result

View File

@ -208,10 +208,7 @@ export default function Dashboard() {
setPipelineLoading(true); setPipelineError(null)
try {
const pid = localStorage.getItem('mitai-jinkendo_active_profile')||''
const r = await fetch('/api/insights/pipeline', {
method:'POST', headers: pid ? {'X-Profile-Id':pid} : {}
})
if (!r.ok) throw new Error(await r.text())
await api.insightPipeline()
await load()
} catch(e) {
setPipelineError('Fehler: '+e.message)

View File

@ -924,7 +924,7 @@ export default function History() {
setLoadingSlug(slug)
try {
const pid=localStorage.getItem('bodytrack_active_profile')||''
const r=await fetch(`/api/insights/run/${slug}`,{method:'POST',headers:pid?{'X-Profile-Id':pid}:{}})
const r=await api.runInsight(slug)
if(!r.ok) throw new Error(await r.text())
const ins=await api.latestInsights()
setInsights(Array.isArray(ins)?ins:[])

View File

@ -335,7 +335,7 @@ export default function NutritionPage() {
const [corr, wkly, prof] = await Promise.all([
nutritionApi.nutritionCorrelations(),
nutritionApi.nutritionWeekly(16),
fetch('/api/profile').then(r=>r.json()),
api.getActiveProfile(),
])
setCorr(Array.isArray(corr)?corr:[])
setWeekly(Array.isArray(wkly)?wkly:[])

View File

@ -23,6 +23,7 @@ const jput=(d)=>({method:'PUT', headers:{'Content-Type':'application/json'},body
export const api = {
// Profiles
getActiveProfile: () => req('/profile'),
listProfiles: () => req('/profiles'),
createProfile: (d) => req('/profiles', json(d)),
updateProfile: (id,d) => req(`/profiles/${id}`, jput(d)),
@ -82,6 +83,8 @@ export const api = {
// Stats & AI
getStats: () => req('/stats'),
insightTrend: () => req('/insights/trend',{method:'POST'}),
listPrompts: () => req('/prompts'),
runInsight: (slug) => req(`/insights/run/${slug}`,{method:'POST'}),
insightPipeline: () => req('/insights/pipeline',{method:'POST'}),
listInsights: () => req('/insights'),
latestInsights: () => req('/insights/latest'),