--- 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": [] }, { "name": "routers", "type": "Record<`string`, `Router`[]\\>", "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 \\>", "description": "the middleware function. Should return a middleware function.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### 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`\>\>[] \\>[]", "type": "`RequestHandler`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, Record<`string`, `any`\\>\\>[]", "optional": false, "defaultValue": "", "description": "", "expandable": false, "children": [] } ]} /> ___ ### validateMiddleware\_ **validateMiddleware_**(`fn`): `void` Validates a middleware function, throws if fn is not of type function. #### Parameters #### Returns `void`