Skip to main content
Skip to main content
You're viewing the documentation for v1, which isn't the latest Medusa version.Latest documentation

MiddlewareService

Orchestrates dynamic middleware registered through the Medusa Middleware API

constructor​


Properties​

postAuthentication_middlewareType[]Required
preAuthentication_middlewareType[]Required
preCartCreation_RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]Required
routersRecord<string, Router[]>Required

Methods​

addRouter​

Parameters​

pathstringRequired
routerRouterRequired

Returns​

voidvoidRequired

getRouters​

Parameters​

pathstringRequired

Returns​

Router[]Router[]Required

validateMiddleware_​

Validates a middleware function, throws if fn is not of type function.

Parameters​

fnunknownRequired
the middleware function to validate.

Returns​

voidvoidRequired
nothing if the middleware is a function

addPostAuthentication​

Adds a middleware function to be called after authentication is completed.

Parameters​

middlewaremiddlewareHandlerTypeRequired
the middleware function. Should return a middleware function.
optionsRecord<string, unknown>Required
the arguments that will be passed to the middleware

Returns​

voidvoidRequired
void

addPreAuthentication​

Adds a middleware function to be called before authentication is completed.

Parameters​

middlewaremiddlewareHandlerTypeRequired
the middleware function. Should return a middleware function.
optionsRecord<string, unknown>Required
the arguments that will be passed to the middleware

Returns​

voidvoidRequired
void

addPreCartCreation​

Adds a middleware function to be called before cart creation

Parameters​

middlewareRequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>Required
the middleware function. Should return a middleware function.

Returns​

voidvoidRequired
Adds a middleware function to be called before cart creation

usePostAuthentication​

Adds post authentication middleware to an express app.

Parameters​

appRouterRequired
the express app to add the middleware to

Returns​

voidvoidRequired
Adds post authentication middleware to an express app.

usePreAuthentication​

Adds pre authentication middleware to an express app.

Parameters​

appRouterRequired
the express app to add the middleware to

Returns​

voidvoidRequired
Adds pre authentication middleware to an express app.

usePreCartCreation​

Returns​

RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]Required
Was this section helpful?