* docs improvements and changes * updated module definition * modules + dml changes * fix build * fix vale error * fix lint errors * fixes to stripe docs * fix condition * fix condition * fix module defintion * fix checkout * disable UI action * change oas preview action * flatten provider module options * fix lint errors * add module link docs * pr comments fixes * fix vale error * change node engine version * links -> linkable * add note about database name * small fixes * link fixes * fix response code in api reference * added migrations step
110 lines
2.7 KiB
Plaintext
110 lines
2.7 KiB
Plaintext
import { CodeTabs, CodeTab } from "docs-ui"
|
|
|
|
export const metadata = {
|
|
title: `User Module`,
|
|
}
|
|
|
|
# {metadata.title}
|
|
|
|
The User Module is the `@medusajs/user` NPM package that provides user-related features in your Medusa and Node.js applications.
|
|
|
|
## Features
|
|
|
|
### User Management
|
|
|
|
Manage and store your users through Create, Read, Update, and Delete (CRUD) operations:
|
|
|
|
```ts
|
|
const user = await userModuleService.createUsers({
|
|
email: "user@example.com",
|
|
first_name: "John",
|
|
last_name: "Smith",
|
|
})
|
|
```
|
|
|
|
### Invite Users
|
|
|
|
Invite users to join your store and manage those invites, with expiry and revalidation features.
|
|
|
|
```ts
|
|
const invite = await userModuleService.createInvites({
|
|
email: "user2@example.com",
|
|
})
|
|
|
|
// refresh token later
|
|
await userModuleService.refreshInviteTokens([invite.id])
|
|
```
|
|
|
|
---
|
|
|
|
## Configure User Module
|
|
|
|
Refer to [this documentation](./module-options/page.mdx) for details on the module's options.
|
|
|
|
---
|
|
|
|
## How to Use User Module's Service
|
|
|
|
You can use the User Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.USER` imported from `@medusajs/modules-sdk`.
|
|
|
|
For example:
|
|
|
|
<CodeTabs groupId="resource-type">
|
|
<CodeTab label="API Route" value="api-route">
|
|
|
|
```ts title="src/api/store/custom/route.ts"
|
|
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
|
|
import { IUserModuleService } from "@medusajs/types"
|
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
|
|
|
export async function GET(
|
|
req: MedusaRequest,
|
|
res: MedusaResponse
|
|
): Promise<void> {
|
|
const userModuleService: IUserModuleService = req.scope.resolve(
|
|
ModuleRegistrationName.USER
|
|
)
|
|
|
|
res.json({
|
|
users: await userModuleService.listUsers(),
|
|
})
|
|
}
|
|
```
|
|
|
|
</CodeTab>
|
|
<CodeTab label="Subscriber" value="subscribers">
|
|
|
|
```ts title="src/subscribers/custom-handler.ts"
|
|
import { SubscriberArgs } from "@medusajs/medusa"
|
|
import { IUserModuleService } from "@medusajs/types"
|
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
|
|
|
export default async function subscriberHandler({ container }: SubscriberArgs) {
|
|
const userModuleService: IUserModuleService = container.resolve(
|
|
ModuleRegistrationName.USER
|
|
)
|
|
|
|
const users = await userModuleService.listUsers()
|
|
}
|
|
```
|
|
|
|
</CodeTab>
|
|
<CodeTab label="Workflow Step" value="workflow-step">
|
|
|
|
```ts title="src/workflows/hello-world/step1.ts"
|
|
import { createStep } from "@medusajs/workflows-sdk"
|
|
import { IUserModuleService } from "@medusajs/types"
|
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
|
|
|
const step1 = createStep("step-1", async (_, { container }) => {
|
|
const userModuleService: IUserModuleService = container.resolve(
|
|
ModuleRegistrationName.USER
|
|
)
|
|
|
|
const users = await userModuleService.listUsers()
|
|
})
|
|
```
|
|
|
|
</CodeTab>
|
|
</CodeTabs>
|