diff --git a/generator/frontend/src/App.tsx b/generator/frontend/src/App.tsx index 6cc64fe..1a4fe9a 100644 --- a/generator/frontend/src/App.tsx +++ b/generator/frontend/src/App.tsx @@ -5,7 +5,7 @@ import { WorkshopScreen } from './screens/WorkshopScreen' import { ResultScreen } from './screens/ResultScreen' import type { WidgetData } from './lib/renderWidgets' import { DEMO_WIDGET_DATA } from './lib/demoData' -import { authHeaders, saveEditToken } from './lib/editToken' +import { fetchMe, type Me } from './lib/auth' export type Achievement = { title: string @@ -49,6 +49,7 @@ const POLL_INTERVAL_MS = 2000 const POLL_TIMEOUT_MS = 120_000 export default function App() { + const [me, setMe] = useState({ login: null }) const [step, setStep] = useState('search') const [username, setUsername] = useState('') const [settings, setSettings] = useState({ ...DEFAULT_SETTINGS }) @@ -72,6 +73,7 @@ export default function App() { }, []) useEffect(() => stopPolling, [stopPolling]) + useEffect(() => { fetchMe().then(setMe) }, []) const startFetch = useCallback((user: string) => { stopPolling() @@ -88,12 +90,8 @@ export default function App() { const r = await fetch(`/api/${encodeURIComponent(user)}/data`) if (aborted.current) return const body = await r.json().catch( - () => ({} as { status?: string; data?: WidgetData; edit_token?: string }) + () => ({} as { status?: string; data?: WidgetData }) ) - // The 202 auto-enroll response surfaces an edit_token exactly once - // per fresh username. Persist it so PATCH /settings and POST - // /refresh can authenticate this browser as the profile owner. - if (body.edit_token) saveEditToken(user, body.edit_token) const status = body.status if (r.status === 200 && status === 'ready' && body.data) { @@ -156,10 +154,8 @@ export default function App() { } const patchRes = await fetch(`/api/${encodeURIComponent(username)}/settings`, { method: 'PATCH', - headers: { - 'Content-Type': 'application/json', - ...authHeaders(username), - }, + credentials: 'include', + headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(backendSettings), }) if (!patchRes.ok && patchRes.status !== 404) { @@ -217,6 +213,8 @@ export default function App() { fetchDone={fetchDone} fetchError={fetchError} widgetData={widgetData} + me={me} + onAuthChange={setMe} /> )} {step === 'result' && ( diff --git a/generator/frontend/src/screens/WorkshopScreen.tsx b/generator/frontend/src/screens/WorkshopScreen.tsx index f3d77dc..916a41f 100644 --- a/generator/frontend/src/screens/WorkshopScreen.tsx +++ b/generator/frontend/src/screens/WorkshopScreen.tsx @@ -2,6 +2,7 @@ import { useState, useMemo, type ReactNode } from 'react' import DOMPurify from 'dompurify' import type { WidgetSettings, Achievement, PerWidgetSettings } from '../App' import { renderAllWidgets, type WidgetData } from '../lib/renderWidgets' +import type { Me } from '../lib/auth' // Defense-in-depth: the client-rendered preview assembles SVG from // GitHub-sourced strings (collaborator logins, repo names) and user-typed @@ -214,6 +215,8 @@ type Props = { fetchDone: boolean fetchError: string | null widgetData: WidgetData | null + me: Me + onAuthChange?: (m: Me) => void } export function WorkshopScreen({