mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(frontend): App fetches /me, removes editToken plumbing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
b2baded94a
commit
8ccc0af1cf
@@ -5,7 +5,7 @@ import { WorkshopScreen } from './screens/WorkshopScreen'
|
|||||||
import { ResultScreen } from './screens/ResultScreen'
|
import { ResultScreen } from './screens/ResultScreen'
|
||||||
import type { WidgetData } from './lib/renderWidgets'
|
import type { WidgetData } from './lib/renderWidgets'
|
||||||
import { DEMO_WIDGET_DATA } from './lib/demoData'
|
import { DEMO_WIDGET_DATA } from './lib/demoData'
|
||||||
import { authHeaders, saveEditToken } from './lib/editToken'
|
import { fetchMe, type Me } from './lib/auth'
|
||||||
|
|
||||||
export type Achievement = {
|
export type Achievement = {
|
||||||
title: string
|
title: string
|
||||||
@@ -49,6 +49,7 @@ const POLL_INTERVAL_MS = 2000
|
|||||||
const POLL_TIMEOUT_MS = 120_000
|
const POLL_TIMEOUT_MS = 120_000
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
|
const [me, setMe] = useState<Me>({ login: null })
|
||||||
const [step, setStep] = useState<Step>('search')
|
const [step, setStep] = useState<Step>('search')
|
||||||
const [username, setUsername] = useState('')
|
const [username, setUsername] = useState('')
|
||||||
const [settings, setSettings] = useState<WidgetSettings>({ ...DEFAULT_SETTINGS })
|
const [settings, setSettings] = useState<WidgetSettings>({ ...DEFAULT_SETTINGS })
|
||||||
@@ -72,6 +73,7 @@ export default function App() {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => stopPolling, [stopPolling])
|
useEffect(() => stopPolling, [stopPolling])
|
||||||
|
useEffect(() => { fetchMe().then(setMe) }, [])
|
||||||
|
|
||||||
const startFetch = useCallback((user: string) => {
|
const startFetch = useCallback((user: string) => {
|
||||||
stopPolling()
|
stopPolling()
|
||||||
@@ -88,12 +90,8 @@ export default function App() {
|
|||||||
const r = await fetch(`/api/${encodeURIComponent(user)}/data`)
|
const r = await fetch(`/api/${encodeURIComponent(user)}/data`)
|
||||||
if (aborted.current) return
|
if (aborted.current) return
|
||||||
const body = await r.json().catch(
|
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
|
const status = body.status
|
||||||
|
|
||||||
if (r.status === 200 && status === 'ready' && body.data) {
|
if (r.status === 200 && status === 'ready' && body.data) {
|
||||||
@@ -156,10 +154,8 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
const patchRes = await fetch(`/api/${encodeURIComponent(username)}/settings`, {
|
const patchRes = await fetch(`/api/${encodeURIComponent(username)}/settings`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
headers: {
|
credentials: 'include',
|
||||||
'Content-Type': 'application/json',
|
headers: { 'Content-Type': 'application/json' },
|
||||||
...authHeaders(username),
|
|
||||||
},
|
|
||||||
body: JSON.stringify(backendSettings),
|
body: JSON.stringify(backendSettings),
|
||||||
})
|
})
|
||||||
if (!patchRes.ok && patchRes.status !== 404) {
|
if (!patchRes.ok && patchRes.status !== 404) {
|
||||||
@@ -217,6 +213,8 @@ export default function App() {
|
|||||||
fetchDone={fetchDone}
|
fetchDone={fetchDone}
|
||||||
fetchError={fetchError}
|
fetchError={fetchError}
|
||||||
widgetData={widgetData}
|
widgetData={widgetData}
|
||||||
|
me={me}
|
||||||
|
onAuthChange={setMe}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{step === 'result' && (
|
{step === 'result' && (
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useState, useMemo, type ReactNode } from 'react'
|
|||||||
import DOMPurify from 'dompurify'
|
import DOMPurify from 'dompurify'
|
||||||
import type { WidgetSettings, Achievement, PerWidgetSettings } from '../App'
|
import type { WidgetSettings, Achievement, PerWidgetSettings } from '../App'
|
||||||
import { renderAllWidgets, type WidgetData } from '../lib/renderWidgets'
|
import { renderAllWidgets, type WidgetData } from '../lib/renderWidgets'
|
||||||
|
import type { Me } from '../lib/auth'
|
||||||
|
|
||||||
// Defense-in-depth: the client-rendered preview assembles SVG from
|
// Defense-in-depth: the client-rendered preview assembles SVG from
|
||||||
// GitHub-sourced strings (collaborator logins, repo names) and user-typed
|
// GitHub-sourced strings (collaborator logins, repo names) and user-typed
|
||||||
@@ -214,6 +215,8 @@ type Props = {
|
|||||||
fetchDone: boolean
|
fetchDone: boolean
|
||||||
fetchError: string | null
|
fetchError: string | null
|
||||||
widgetData: WidgetData | null
|
widgetData: WidgetData | null
|
||||||
|
me: Me
|
||||||
|
onAuthChange?: (m: Me) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export function WorkshopScreen({
|
export function WorkshopScreen({
|
||||||
|
|||||||
Reference in New Issue
Block a user