Documentation / zerotal / auth / BasicAuthMiddleware
Class: BasicAuthMiddleware
Defined in: packages/auth/src/BasicAuthMiddleware.ts:26
HTTP Basic authentication.
Reads the Authorization: Basic header, looks the user up by field, and
verifies the password. On success ctx.user is set for this request only —
no session is created (stateless), so it suits simple API endpoints. On
failure it returns 401 with a WWW-Authenticate challenge, prompting the
browser for credentials.
Example
Router.get("/api/ping", PingController, "show", [BasicAuthMiddleware]);
// Authenticate by a different column / realm:
BasicAuthMiddleware.with({ field: "username", realm: "Admin" })
Extends
Constructors
Constructor
new BasicAuthMiddleware():
BasicAuthMiddleware
Defined in: packages/core/src/middleware/BaseMiddleware.ts:36
Returns
BasicAuthMiddleware
Inherited from
Properties
options
protectedoptions:BasicAuthOptions
Defined in: packages/auth/src/BasicAuthMiddleware.ts:27
Subclasses must declare this with their default option values. TypeScript enforces this at compile time — forgetting it is a type error.
Overrides
Methods
handle()
handle(
http,next):Promise<void|Response>
Defined in: packages/auth/src/BasicAuthMiddleware.ts:29
Parameters
http
next
Returns
Promise<void | Response>
Overrides
with()
staticwith<T,Opts>(this,options): () =>InstanceType<T>
Defined in: packages/core/src/middleware/BaseMiddleware.ts:48
Returns a zero-arg subclass with the given options deep-merged on top of the subclass defaults, usable directly in app.use([...]).
Type Parameters
T
T extends (...args) => BaseMiddleware<any>
Opts
Opts = T extends (...args) => BaseMiddleware<U> ? U : object
Parameters
this
T
options
Partial<Opts>
Returns
() => InstanceType<T>
Inherited from
afterResponse()?
optionalafterResponse(ctx):Promise<void>
Defined in: packages/core/src/middleware/BaseMiddleware.ts:70
Parameters
ctx
Returns
Promise<void>
Inherited from
onError()?
optionalonError(ctx,error):Promise<void>
Defined in: packages/core/src/middleware/BaseMiddleware.ts:71
Parameters
ctx
error
Error
Returns
Promise<void>