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 loadAll = async () => {
const [p, i] = await Promise.all([ const [p, i] = await Promise.all([
fetch('/api/prompts').then(r=>r.json()), api.listPrompts(),
api.listInsights() api.listInsights()
]) ])
setPrompts(Array.isArray(p)?p:[]) setPrompts(Array.isArray(p)?p:[])
@ -128,12 +128,7 @@ export default function Analysis() {
const runPipeline = async () => { const runPipeline = async () => {
setPipelineLoading(true); setError(null); setNewResult(null) setPipelineLoading(true); setError(null); setNewResult(null)
try { try {
const pid = localStorage.getItem('bodytrack_active_profile')||'' const result = await api.insightPipeline()
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()
setNewResult(result) setNewResult(result)
await loadAll() await loadAll()
setTab('run') setTab('run')
@ -145,12 +140,7 @@ export default function Analysis() {
const runPrompt = async (slug) => { const runPrompt = async (slug) => {
setLoading(slug); setError(null); setNewResult(null) setLoading(slug); setError(null); setNewResult(null)
try { try {
const pid = localStorage.getItem('bodytrack_active_profile')||'' const result = await api.runInsight(slug)
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()
setNewResult(result) // show immediately setNewResult(result) // show immediately
await loadAll() // refresh lists await loadAll() // refresh lists
setTab('run') // stay on run tab to see result setTab('run') // stay on run tab to see result

View File

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

View File

@ -924,7 +924,7 @@ export default function History() {
setLoadingSlug(slug) setLoadingSlug(slug)
try { try {
const pid=localStorage.getItem('bodytrack_active_profile')||'' 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()) if(!r.ok) throw new Error(await r.text())
const ins=await api.latestInsights() const ins=await api.latestInsights()
setInsights(Array.isArray(ins)?ins:[]) setInsights(Array.isArray(ins)?ins:[])

View File

@ -335,7 +335,7 @@ export default function NutritionPage() {
const [corr, wkly, prof] = await Promise.all([ const [corr, wkly, prof] = await Promise.all([
nutritionApi.nutritionCorrelations(), nutritionApi.nutritionCorrelations(),
nutritionApi.nutritionWeekly(16), nutritionApi.nutritionWeekly(16),
fetch('/api/profile').then(r=>r.json()), api.getActiveProfile(),
]) ])
setCorr(Array.isArray(corr)?corr:[]) setCorr(Array.isArray(corr)?corr:[])
setWeekly(Array.isArray(wkly)?wkly:[]) 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 = { export const api = {
// Profiles // Profiles
getActiveProfile: () => req('/profile'),
listProfiles: () => req('/profiles'), listProfiles: () => req('/profiles'),
createProfile: (d) => req('/profiles', json(d)), createProfile: (d) => req('/profiles', json(d)),
updateProfile: (id,d) => req(`/profiles/${id}`, jput(d)), updateProfile: (id,d) => req(`/profiles/${id}`, jput(d)),
@ -82,6 +83,8 @@ export const api = {
// Stats & AI // Stats & AI
getStats: () => req('/stats'), getStats: () => req('/stats'),
insightTrend: () => req('/insights/trend',{method:'POST'}), insightTrend: () => req('/insights/trend',{method:'POST'}),
listPrompts: () => req('/prompts'),
runInsight: (slug) => req(`/insights/run/${slug}`,{method:'POST'}),
insightPipeline: () => req('/insights/pipeline',{method:'POST'}), insightPipeline: () => req('/insights/pipeline',{method:'POST'}),
listInsights: () => req('/insights'), listInsights: () => req('/insights'),
latestInsights: () => req('/insights/latest'), latestInsights: () => req('/insights/latest'),