auth/request_context.ts view source
(deps: QueryDeps, account_id: string | null, auth: { account: "none" | "optional" | "required"; actor: "none" | "optional" | "required"; roles?: readonly string[] | undefined; credential_types?: readonly string[] | undefined; required_scope?: string | undefined; }, acting_value: string | undefined): Promise<...> import {apply_authorization_phase} from '@fuzdev/fuz_app/auth/request_context.js'; Apply the dispatcher's authorization phase against the flat-record RouteAuth shape. Shared by the route-spec wrapper, the HTTP RPC dispatcher, and the per-message WS dispatcher. Phase order: pre-authorization 401 → authorization phase → post-authorization 403 → input validation 400.
Pure data — the function does not touch a Hono context. Each transport
passes account_id (extracted from its own credential surface) and
binds the returned AuthorizationResult to its wire shape. The REST
pipeline additionally writes REQUEST_CONTEXT_KEY on c for downstream
require_role / require_credential_types middleware that still reads
the resolved context off the Hono context.
Branching by auth.account × auth.actor:
- Both
'none'→{ok: true, request_context: null}. Public actions never see a RequestContext. account_id == nullon any non-public route → same nullrequest_context. The'required'callers were already rejected at the pre-authorization gate in the dispatcher; only genuine anonymous access on an'optional'axis lands here.actor === 'none'→ builds account-only context via build_account_context. Null lookup →account_vanished500 failure.actor === 'required'→ resolves the actor fromacting_value(or single-actor account); failures map to 400 / 500.actor === 'optional'→ same as'required'except multi-actor accounts without anactingvalue fall back to account-only context (noactor_required400). Badactingids still 400.
500 branches stay distinct: ERROR_NO_ACTORS_ON_ACCOUNT (signup invariant violation), ERROR_ACCOUNT_VANISHED (torn read after resolve).
deps
account_id
string | nullauth
{ account: "none" | "optional" | "required"; actor: "none" | "optional" | "required"; roles?: readonly string[] | undefined; credential_types?: readonly string[] | undefined; required_scope?: string | undefined; }acting_value
string | undefinedreturns
Promise<AuthorizationResult>