authenticated
@rotorsoft/act-root / act-http/src/hono / authenticated
Function: authenticated()
authenticated(
extractor):MiddlewareHandler<{Variables:ActMiddlewareVariables; },string, { },Response&TypedResponse<{code?:string;detail?:string;error:string; },401,"json">>
Defined in: libs/act-http/src/hono/index.ts:171
Build a Hono middleware that runs an ActorExtractor once
per call and stashes the resolved Actor under
c.set("actor", ...) so downstream routes can read it via
c.get("actor"). The generator at hono uses this
internally; it's also exported so hosts that want to compose
their own route chain (logging, tracing, custom auth flavors)
can wire it directly:
import { Hono } from "hono";
import { authenticated, type ActMiddlewareVariables } from "@rotorsoft/act-http/hono";
const api = new Hono<{ Variables: ActMiddlewareVariables }>();
api.use("*", authenticated((c) => resolveUserFromJwt(c)));
api.get("/me", (c) => c.json(c.get("actor"))); // typed
Errors thrown by the extractor surface as 401 Unauthorized with
the shared ApiError envelope. Mounted on a route
(api.get("/me", authenticated(extract), handler)), the 401 is in
the route's type, so hc and testClient see it.
Parameters
extractor
ActorExtractor<Context<any, any, { }>>
Returns
MiddlewareHandler<{ Variables: ActMiddlewareVariables; }, string, { }, Response & TypedResponse<{ code?: string; detail?: string; error: string; }, 401, "json">>