fix(404): stop returning an empty-bodied 404 from the account pages and the auth guard #242
Inga granskare
Etiketter
Inga etiketter
area/backups
area/ci
area/control-panel
area/identity
area/infra
area/observability
area/payments
area/security
area/storage
area/web
blocked
needs-info
needs-triage
ready-for-implementation
type
bug
type
chore
type
docs
type
epic
type
feature
type
task
wontfix
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Inget förfallodatum satt.
Beroenden
Inga beroenden satta
Referens
bitborg/bitborg-web!242
Läser in…
Hänvisa till i nytt ärende
Ingen beskrivning angiven.
Ta bort grenen "work/139"
Borttagning av en gren är permanent. Även om den borttagna grenen kan fortsätta existera en kort tid innan den faktiskt tas bort, kan det INTE ångras i de flesta fall. Vill du fortsätta?
Follow-up to #134, which fixed the same bug shape in the
[slug]routes.new Response(null, { status: 404 })sends a null body, so the browser gets a 404 with nothing to render.account.astroanden/account.astroare mechanical: the sameAstro.rewrite(getRelativeLocaleUrl(lang, "/404"))the slug routes use.guard.tsis the awkward half. It returns bareResponseobjects from a library function, so it has noAstrocontext and no language. The guard now signals instead of rendering:AdminGuardandUserGuardare a three-way union ofok,forbidden(unchanged, still an embedded 403) andnot-configured(no Response). One helper,notConfiguredRedirect(lang), builds the redirect, and every caller uses it. Threading Astro context into the library would have been the larger change.Every caller of
requireUserandrequireAdminwas checked before editing.requireAdminhas no callers at all, which is pre-existing dead code and left alone. All fourrequireUsercallers are full browser navigations, form POSTs or an emailed GET link, so the empty body was user-facing in each. Three of them only knewlangfrom parsed form data, sorequest.formData()moved above the guard call. Only body parsing moved. No privileged work happens before the auth gate.login.tsandcallback.tshad the same bug and the same consequence. They establish a session rather than consume one, so they callnotConfiguredRedirectdirectly. No third mechanism.Deliberately left alone:
src/pages/api/signup.ts:76and the two captcha endpoints. Those are fetch calls from client JavaScript, where an empty body is correct.src/lib/account-page.ts:23. Unreachable now that the page-level gate onaccount.astrointercepts first.Tests:
src/lib/auth/guard.test.tscovers the not-configured branch of both guards, the redirect target per language, and both newly fixed routes.Verified:
pnpm lint,pnpm check,pnpm test(364 passed).grep -rn 'Response(null' src/leaves only the four out-of-scope call sites above and two comments referencing the old pattern.Closes #139
new Response(null, { status: 404 }) sends a null body, so the browser renders nothing. account.astro/en/account.astro now rewrite to /404 like the [slug] routes (#134). guard.ts has no Astro context, so it signals "not-configured" instead of embedding a Response, and each caller turns that into a redirect to the localized branded 404 page.eadba0eb2d3376aec0ce