feat(frontend): App fetches /me, removes editToken plumbing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
shay
2026-04-19 19:12:36 -04:00
co-authored by Claude Sonnet 4.6
parent b2baded94a
commit 8ccc0af1cf
2 changed files with 11 additions and 10 deletions
+8 -10
View File
@@ -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<Me>({ login: null })
const [step, setStep] = useState<Step>('search')
const [username, setUsername] = useState('')
const [settings, setSettings] = useState<WidgetSettings>({ ...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' && (