MiddlewareService
Orchestrates dynamic middleware registered through the Medusa Middleware API
constructor
Properties
postAuthentication_middlewareType[]RequiredpreAuthentication_middlewareType[]RequiredpreCartCreation_RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]RequiredroutersRecord<string, Router[]>RequiredMethods
addPostAuthentication
Adds a middleware function to be called after authentication is completed.
Parameters
middlewaremiddlewareHandlerTypeRequiredthe middleware function. Should return a
middleware function.
optionsRecord<string, unknown>Requiredthe arguments that will be passed to the
middleware
Returns
voidvoidvoid
addPreAuthentication
Adds a middleware function to be called before authentication is completed.
Parameters
middlewaremiddlewareHandlerTypeRequiredthe middleware function. Should return a
middleware function.
optionsRecord<string, unknown>Requiredthe arguments that will be passed to the
middleware
Returns
voidvoidvoid
addPreCartCreation
Adds a middleware function to be called before cart creation
Parameters
middlewareRequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>Requiredthe middleware function. Should return a
middleware function.
Returns
voidvoidaddRouter
Parameters
pathstringRequiredrouterRouterRequiredReturns
voidvoidgetRouters
Parameters
pathstringRequiredReturns
Router[]Router[]RequiredusePostAuthentication
Adds post authentication middleware to an express app.
Parameters
appRouterRequiredthe express app to add the middleware to
Returns
voidvoidusePreAuthentication
Adds pre authentication middleware to an express app.
Parameters
appRouterRequiredthe express app to add the middleware to
Returns
voidvoidusePreCartCreation
Returns
RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]RequiredvalidateMiddleware_
Validates a middleware function, throws if fn is not of type function.
Parameters
fnunknownRequiredthe middleware function to validate.
Returns
voidvoidnothing if the middleware is a function
Was this section helpful?