Middleware transform framework and runtime specific request/response objects passed to Auth.handleRequest()
into Lucia’s specific API.
Middleware
#
type Middleware<_Args extends any[] = any> = (context: {
args: _Args;
env: "DEV" | "PROD";
sessionCookieName: string;
}) => RequestContext;
Parameters#
name | type | description |
---|
context.args | _Args | Arguments passed to Auth.handleRequest() when the middleware is used |
context.env | "DEV" | "PROD" | Project env configuration |
sessionCookieName | string | Session cookie name defined in sessionCookie.name configuration (or default name if undefined) |
Generics#
RequestContext
#
type RequestContext = {
request: LuciaRequest;
setCookie: (cookie: Cookie) => void;
};
Properties#
setCookie()
#
Sets the provided cookie.
const setCookie: (cookie: Cookie) => void;
Parameters#
name | type | description |
---|
cookie | Cookie | Cookie to set |
Typing Middleware
#
When creating a middleware, it’s crucial that you explicitly declare type Middleware
so that parameters context.args
is properly typed.
export const customMiddleware = (): Middleware<[Request]> => {
return (context) => {
return {
// ...
};
};
};