fix: add auth token to all API calls (prompts, insights, pipeline)
This commit is contained in:
parent
89b6c0b072
commit
5091dfd1ce
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:[])
|
||||
|
|
|
|||
|
|
@ -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:[])
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user