Skip to main content
Skip to main content

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

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

voidvoid
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

voidvoid
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

voidvoid

addRouter

Parameters

pathstringRequired
routerRouterRequired

Returns

voidvoid

getRouters

Parameters

pathstringRequired

Returns

Router[]Router[]Required

usePostAuthentication

Adds post authentication middleware to an express app.

Parameters

appRouterRequired
the express app to add the middleware to

Returns

voidvoid

usePreAuthentication

Adds pre authentication middleware to an express app.

Parameters

appRouterRequired
the express app to add the middleware to

Returns

voidvoid

usePreCartCreation

Returns

RequestHandler&#60;ParamsDictionary, any, any, ParsedQs, Record&#60;string, any&#62;&#62;[]RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]Required

validateMiddleware_

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

Parameters

fnunknownRequired
the middleware function to validate.

Returns

voidvoid
nothing if the middleware is a function
Was this section helpful?