docs: update middlewares to use defineMiddlewares (#8283)
This commit is contained in:
@@ -27,13 +27,16 @@ When you protect routes with the `authenticate` middleware, you specify in its f
|
||||
For example:
|
||||
|
||||
export const highlights = [
|
||||
["8", `"user"`, "The actor type that must be authenticated to access the specified routes."]
|
||||
["11", `"user"`, "The actor type that must be authenticated to access the specified routes."]
|
||||
]
|
||||
|
||||
```ts title="src/api/middlewares.ts" highlights={highlights}
|
||||
import { MiddlewaresConfig, authenticate } from "@medusajs/medusa"
|
||||
import {
|
||||
defineMiddlewares,
|
||||
authenticate
|
||||
} from "@medusajs/medusa"
|
||||
|
||||
export const config: MiddlewaresConfig = {
|
||||
export default defineMiddlewares({
|
||||
routes: [
|
||||
{
|
||||
matcher: "/custom/admin*",
|
||||
@@ -42,7 +45,7 @@ export const config: MiddlewaresConfig = {
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
By specifying `user` as the first parameter of `authenticate`, only authenticated users of actor type `user` can access API routes starting with `/custom/admin`.
|
||||
|
||||
@@ -176,15 +176,18 @@ The last step is to apply the `authenticate` middleware on the API routes that r
|
||||
To do that, create the file `src/api/middlewares.ts` with the following content:
|
||||
|
||||
export const middlewareHighlights = [
|
||||
["9", "authenticate", "Require the user to be authenticated to access the `/manager` API route when sending a `POST` request."],
|
||||
["10", "allowUnregistered", "The user doesn't need to be registered to access the API route."],
|
||||
["17", "authenticate", "Require the user to be authenticated as a manager when accessing `/manager/me` API routes."]
|
||||
["12", "authenticate", "Require the user to be authenticated to access the `/manager` API route when sending a `POST` request."],
|
||||
["13", "allowUnregistered", "The user doesn't need to be registered to access the API route."],
|
||||
["20", "authenticate", "Require the user to be authenticated as a manager when accessing `/manager/me` API routes."]
|
||||
]
|
||||
|
||||
```ts title="src/api/middlewares.ts" highlights={middlewareHighlights}
|
||||
import { MiddlewaresConfig, authenticate } from "@medusajs/medusa"
|
||||
import {
|
||||
defineMiddlewares,
|
||||
authenticate
|
||||
} from "@medusajs/medusa"
|
||||
|
||||
export const config: MiddlewaresConfig = {
|
||||
export default defineMiddlewares({
|
||||
routes: [
|
||||
{
|
||||
matcher: "/manager",
|
||||
@@ -202,7 +205,7 @@ export const config: MiddlewaresConfig = {
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
This applies middlewares on two route patterns:
|
||||
|
||||
Reference in New Issue
Block a user