Documentation / @zerotal/monitor / MonitorAuthMiddleware
Class: MonitorAuthMiddleware
Defined in: monitor/src/middleware/MonitorAuthMiddleware.ts:10
A single step in a middleware pipeline.
Contract
A pipe does exactly one of three things:
- Continue:
return next()to run the rest of the chain. - Short-circuit: produce a
Responseand stop. Eitherreturnit directly, or setctx.responseandreturn(void). Do NOT callnext(). - Wrap:
const res = await next(), inspect/transformres, then return the (possibly new)Response— or just mutatectx.responseand return void.
ctx.response is the canonical store: returning a Response is sugar the
pipeline mirrors onto it, and a void return leaves it untouched (so it can
never erase a response a deeper pipe already set).
Example
class RequireAuth implements Pipe<HttpContext> {
async handle(ctx: HttpContext, next: NextFn): Promise<Response | void> {
if (!ctx.user) {
return Response.json({ message: 'Unauthenticated.' }, { status: 401 });
}
return next();
}
}
Implements
Constructors
Constructor
new MonitorAuthMiddleware():
MonitorAuthMiddleware
Returns
MonitorAuthMiddleware
Methods
handle()
handle(
http,next):Promise<void|Response>
Defined in: monitor/src/middleware/MonitorAuthMiddleware.ts:11
Parameters
http
next
Returns
Promise<void | Response>