User Module

In this section of the documentation, you will find resources to learn more about the User Module and how to use it in your application.

Medusa has user related features available out-of-the-box through the User Module. A module is a standalone package that provides features for a single domain. Each of Medusa's commerce features are placed in commerce modules, such as this User Module.

NoteLearn more about why modules are isolated in this documentation.

User Features#


How to Use User Module's Service#

In your Medusa application, you build flows around commerce modules. A flow is built as a Workflow, which is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.

You can build custom workflows and steps. You can also re-use Medusa's workflows and steps, which are provided by the @medusajs/medusa/core-flows package.

For example:

src/workflows/create-user.ts
1import { 2  createWorkflow, 3  WorkflowResponse,4  createStep,5  StepResponse,6} from "@medusajs/framework/workflows-sdk"7import { Modules } from "@medusajs/framework/utils"8
9const createUserStep = createStep(10  "create-user",11  async ({}, { container }) => {12    const userModuleService = container.resolve(Modules.USER)13
14    const user = await userModuleService.createUsers({15      email: "user@example.com",16      first_name: "John",17      last_name: "Smith",18    })19
20    return new StepResponse({ user }, user.id)21  },22  async (userId, { container }) => {23    if (!userId) {24      return25    }26    const userModuleService = container.resolve(Modules.USER)27
28    await userModuleService.deleteUsers([userId])29  }30)31
32export const createUserWorkflow = createWorkflow(33  "create-user",34  () => {35    const { user } = createUserStep()36
37    return new WorkflowResponse({38      user,39    })40  }41)

You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:

Learn more about workflows in this documentation.


Configure User Module#

The User Module accepts options for further configurations. Refer to this documentation for details on the module's options.


Was this page helpful?
Edit this page