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; }, acting_value: string | undefined): Promise<...> 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-validation 401 โ input validation 400 โ authorization phase โ post-authorization 403.
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 == null on any non-public route โ same null
request_context. The 'required' callers were already rejected at
the pre-validation 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_vanished 500 failure.
- actor === 'required' โ resolves the actor from acting_value (or
single-actor account); failures map to 400 / 500.
- actor === 'optional' โ same as 'required' except multi-actor
accounts without an acting value fall back to account-only context
(no actor_required 400). Bad acting ids 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; }acting_value
string | undefinedreturns
Promise<AuthorizationResult>