--- displayed_sidebar: servicesSidebar --- import ParameterTypes from "@site/src/components/ParameterTypes" # MiddlewareService Orchestrates dynamic middleware registered through the Medusa Middleware API ## Constructors #### constructor `**new MiddlewareService**()` ## Properties `", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> ## Methods #### addPostAuthentication `**addPostAuthentication**(middleware, options): void` Adds a middleware function to be called after authentication is completed. ##### Parameters `", "description": "the arguments that will be passed to the middleware", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> ##### Returns `void` ___ #### addPreAuthentication `**addPreAuthentication**(middleware, options): void` Adds a middleware function to be called before authentication is completed. ##### Parameters `", "description": "the arguments that will be passed to the middleware", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> ##### Returns `void` ___ #### addPreCartCreation `**addPreCartCreation**(middleware): void` Adds a middleware function to be called before cart creation ##### Parameters ##### Returns `void` ___ #### addRouter `**addRouter**(path, router): void` ##### Parameters ##### Returns `void` ___ #### getRouters `**getRouters**(path): Router[]` ##### Parameters ##### Returns Router[] ___ #### usePostAuthentication `**usePostAuthentication**(app): void` Adds post authentication middleware to an express app. ##### Parameters ##### Returns `void` ___ #### usePreAuthentication `**usePreAuthentication**(app): void` Adds pre authentication middleware to an express app. ##### Parameters ##### Returns `void` ___ #### usePreCartCreation `**usePreCartCreation**(): RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]` ##### Returns RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[] ___ #### validateMiddleware\_ `**validateMiddleware_**(fn): void` Validates a middleware function, throws if fn is not of type function. ##### Parameters ##### Returns `void`