chore: sync in-progress work across marketing, admin, API and tests
Snapshot of uncommitted work that had accumulated in the tree alongside the Turnstile changes: - marketing pages, SEO helpers (lib/seo.ts, lib/marketing/) and structured data - admin billing actions and a per-user portfolio view, plus an admin error boundary - rate limiting (lib/rate-limit.ts) applied across the /api/v1 surface - CSP and proxy adjustments, accounting/webhook lib updates - Playwright config and an e2e/unit test suite - next bumped to ^16.3.4 with the lockfile regenerated - generated AGENTS.md / CLAUDE.md Authored by other sessions working in this tree; committed here so the Turnstile work could be pushed without leaving the tree dirty. Typecheck passes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
8f90347659
commit
1d02598786
+18
-18
@@ -12,43 +12,43 @@ interface UserState {
|
||||
|
||||
export function useUser(): UserState {
|
||||
const { data: session, isPending } = useSession()
|
||||
const [profile, setProfile] = useState<Profile | null>(null)
|
||||
const [profileLoading, setProfileLoading] = useState(true)
|
||||
|
||||
// The fetched profile is stored together with the user id it belongs to, so
|
||||
// "loaded" is DERIVED rather than tracked in a second state variable. That
|
||||
// removes the synchronous setState in the effect body (which caused cascading
|
||||
// renders) and, as a bonus, stops a previous user's profile from flashing
|
||||
// while a new one loads.
|
||||
const [fetched, setFetched] = useState<{ userId: string; profile: Profile | null } | null>(null)
|
||||
|
||||
const userId = session?.user?.id
|
||||
|
||||
useEffect(() => {
|
||||
if (!userId) return
|
||||
let active = true
|
||||
if (!userId) {
|
||||
setProfile(null)
|
||||
setProfileLoading(false)
|
||||
return
|
||||
}
|
||||
setProfileLoading(true)
|
||||
|
||||
fetch("/api/profile")
|
||||
.then((r) => (r.ok ? r.json() : { profile: null }))
|
||||
.then((data) => {
|
||||
if (active) {
|
||||
setProfile(data.profile ?? null)
|
||||
setProfileLoading(false)
|
||||
}
|
||||
if (active) setFetched({ userId, profile: data.profile ?? null })
|
||||
})
|
||||
.catch(() => {
|
||||
if (active) {
|
||||
setProfile(null)
|
||||
setProfileLoading(false)
|
||||
}
|
||||
if (active) setFetched({ userId, profile: null })
|
||||
})
|
||||
|
||||
return () => {
|
||||
active = false
|
||||
}
|
||||
}, [userId])
|
||||
|
||||
const isCurrent = !!userId && fetched?.userId === userId
|
||||
|
||||
return {
|
||||
user: session?.user
|
||||
? { id: session.user.id, email: session.user.email, name: session.user.name }
|
||||
: null,
|
||||
profile,
|
||||
loading: isPending || profileLoading,
|
||||
profile: isCurrent ? (fetched?.profile ?? null) : null,
|
||||
// Signed out: nothing to load. Signed in: loading until this user's profile
|
||||
// has actually come back.
|
||||
loading: isPending || (!!userId && !isCurrent),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user