docs: preparations for preview (#7267)
* configured base paths + added development banner * fix typelist site url * added navbar and sidebar badges * configure algolia filters * remove AI assistant * remove unused imports * change navbar text and badge * lint fixes * fix build error * add to api reference rewrites * fix build error * fix build errors in user-guide * fix feedback component * add parent title to pagination * added breadcrumbs component * remove user-guide links * resolve todos * fix details about authentication * change documentation title * lint content
This commit is contained in:
1 parent
3e3b8a483f
commit
728c5ee53c
62 files changed
+855
-506
No files matched your search
@@ -118,36 +118,43 @@ In the route handler, you resolve the `UserService`, and then use it to retrieve
|
||||
|
||||
## Protect Custom API Routes
|
||||
|
||||
To protect custom API Routes that don’t start with `/store/me` or `/admin`, apply one of the following middlewares exported by the `@medusajs/medusa` package on your routes:
|
||||
|
||||
- `authenticate`: only authenticated admin users can access the API Route.
|
||||
- `authenticateCustomer`: customer authentication isn’t required, but if a customer is logged in, it attaches their ID to the `MedusaRequest` object's `user.customer_id`.
|
||||
- `requireCustomerAuthentication`: only authenticated customers can access the API Route.
|
||||
To protect custom API Routes that don’t start with `/store/me` or `/admin`, use the `authenticate` middleware imported from `@medusajs/medusa`.
|
||||
|
||||
For example:
|
||||
|
||||
export const highlights = [
|
||||
["11", "authenticate", "Only authenticated admin users can access routes starting with `/custom/admin`"],
|
||||
["15", "requireCustomerAuthentication", "Only authenticated customers can access routes starting with `/custom/customers`"]
|
||||
["17", "authenticate", "Only authenticated customers can access routes starting with `/custom/customers`"]
|
||||
]
|
||||
|
||||
```ts title="src/api/middlewares.ts" highlights={highlights}
|
||||
import {
|
||||
// TODO update import
|
||||
import {
|
||||
authenticate,
|
||||
requireCustomerAuthentication,
|
||||
type MiddlewaresConfig,
|
||||
} from "@medusajs/medusa"
|
||||
} from "@medusajs/medusa/dist/utils/authenticate-middleware"
|
||||
|
||||
export const config: MiddlewaresConfig = {
|
||||
routes: [
|
||||
{
|
||||
matcher: "/custom/admin*",
|
||||
middlewares: [authenticate()],
|
||||
middlewares: [
|
||||
authenticate("admin", ["session", "bearer", "api-key"]),
|
||||
],
|
||||
},
|
||||
{
|
||||
matcher: "/custom/customer*",
|
||||
middlewares: [requireCustomerAuthentication()],
|
||||
middlewares: [
|
||||
authenticate("store", ["session", "bearer"]),
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
The `authenticate` middleware function accepts three parameters:
|
||||
|
||||
1. The scope of authentication. Use `admin` for authenticating admin users, and `store` for authenticating customers.
|
||||
2. An array of the types of authentication methods allowed. Both `admin` and `store` scopes support `session` and `bearer`. The `admin` scope also supports the `api-key` authentication method.
|
||||
3. An optional object of options having the following properties:
|
||||
1. `allowUnauthenticated`: (default: `false`) A boolean indicating whether authentication is required. For example, you may have an API route where you want to access the logged-in customer if available, but guest customers can still access it too. In that case, enable the `allowUnauthenticated` option.
|
||||
2. `allowUnregistered`: (default: `false`) A boolean indicating whether new users can be authenticated.
|
||||
@@ -77,7 +77,7 @@ const deletedRecords = await helloModuleService
|
||||
.listMySoftDeletables({
|
||||
// ...
|
||||
}, {
|
||||
withDeleted: true
|
||||
withDeleted: true,
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
@@ -39,8 +39,6 @@ export const config: SubscriberConfig = {
|
||||
|
||||
This logs the product ID received in the `ProductService.Events.CREATED` (`product-created`) event’s data payload to the console.
|
||||
|
||||
{/* TODO check first if the events list is still correct */}
|
||||
## List of Events with Data Payload
|
||||
|
||||
{/* ## List of Events with Data Payload
|
||||
|
||||
Refer to [this reference](!resources!/events-reference) for a full list of events emitted by Medusa and their data payloads. */}
|
||||
Refer to [this reference](!resources!/events-reference) for a full list of events emitted by Medusa and their data payloads.
|
||||
@@ -79,9 +79,9 @@ The `CustomProductData` data model has a `product_id` field to reference the pro
|
||||
|
||||
When you add a new data model, make sure to:
|
||||
|
||||
- Create a migration for it.
|
||||
- Add it to the second parameter of the main service's factory function.
|
||||
- Add it to the container and connection loaders.
|
||||
- [Create a migration for it.](../../../basics/data-models/page.mdx#create-a-migration)
|
||||
- [Add it to the second parameter of the main service's factory function.](../service-factory/page.mdx#abstractModuleServiceFactory-parameters)
|
||||
- Add it to the [container](../container/page.mdx) and [connection](../connection-loader/page.mdx) loaders.
|
||||
|
||||
</Note>
|
||||
|
||||
@@ -120,8 +120,8 @@ class HelloModuleService extends ModulesSdkUtils
|
||||
{
|
||||
name: ["my_custom"],
|
||||
args: {
|
||||
entity: MyCustom.name
|
||||
}
|
||||
entity: MyCustom.name,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["custom_product_data"],
|
||||
@@ -157,23 +157,23 @@ This creates a relationship to the `Product` data model of the Product Module us
|
||||
name: "serviceName",
|
||||
type: "`string`",
|
||||
optional: false,
|
||||
description: "The name of the module (as added in `medusa-config.js`)."
|
||||
description: "The name of your module (as added in `medusa-config.js`)."
|
||||
},
|
||||
{
|
||||
name: "primaryKeys",
|
||||
type: "`string[]`",
|
||||
optional: false,
|
||||
description: "The primary key field names used in the module's data models.",
|
||||
description: "The primary key field names used in your module's data models.",
|
||||
},
|
||||
{
|
||||
name: "alias",
|
||||
type: "`object[]`",
|
||||
description: "The alias definitions for each data model in the module. This allows other modules to reference your module's data models in relationships.",
|
||||
description: "The alias definitions for each data model in your module. This allows other modules to reference your module's data models in relationships.",
|
||||
children: [
|
||||
{
|
||||
name: "name",
|
||||
type: "`string[]`",
|
||||
description: "The alias names used later when fetching or referencing the data in the model."
|
||||
description: "The alias names of a data model used later when fetching or referencing the data model."
|
||||
},
|
||||
{
|
||||
name: "args",
|
||||
@@ -197,19 +197,19 @@ This creates a relationship to the `Product` data model of the Product Module us
|
||||
{
|
||||
name: "relationships",
|
||||
type: "`object[]`",
|
||||
description: "The module's relationships to other modules.",
|
||||
description: "Your module's relationships to other modules.",
|
||||
children: [
|
||||
{
|
||||
name: "serviceName",
|
||||
type: "`string`",
|
||||
optional: false,
|
||||
description: "The name of the module (as added in `medusa-config.js`) that this relationship is referencing. If you’re referencing a Medusa commerce module, use the `Modules` enum imported from `@medusajs/modules-sdk`."
|
||||
description: "The name of the module (as added in `medusa-config.js`) that this relationship is referencing. When referencing a Medusa commerce module, use the `Modules` enum imported from `@medusajs/modules-sdk`."
|
||||
},
|
||||
{
|
||||
name: "alias",
|
||||
type: "`string`",
|
||||
optional: false,
|
||||
description: "The alias of the data model you’re referencing in the other module. You can find it in the `__joinerConfig` method of the other module."
|
||||
description: "The alias of the data model you’re referencing in the other module. You can find it in the `__joinerConfig` method of the other module's service."
|
||||
},
|
||||
{
|
||||
name: "primaryKey",
|
||||
|
||||
@@ -70,7 +70,7 @@ class HelloModuleService extends ModulesSdkUtils
|
||||
//...
|
||||
|
||||
this.options_ = moduleOptions || {
|
||||
capitalize: false
|
||||
capitalize: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,14 +98,14 @@ const updateProduct = createStep(
|
||||
|
||||
return {
|
||||
...variant,
|
||||
options: variantOptions
|
||||
options: variantOptions,
|
||||
}
|
||||
}),
|
||||
options: options.map((option) => ({
|
||||
...option,
|
||||
values: option.values.map((value) => value.value)
|
||||
values: option.values.map((value) => value.value),
|
||||
})),
|
||||
type_id: type.id
|
||||
type_id: type.id,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user