User Module
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:
Invite Users
Invite users to join your store and manage those invites, with expiry and revalidation features.
Configure User Module
After installing the @medusajs/user
package in your Medusa application, add it to the modules
object in medusa-config.js
:
medusa-config.js
Module Options
Refer to this documentation 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 dependency container the resource ModuleRegistrationName.USER
imported from @medusajs/modules-sdk
.
For example:
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IUserModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const userModuleService: IUserModuleService =
req.scope.resolve(ModuleRegistrationName.USER)
res.json({
users: await userModuleService.list(),
})
}
import { SubscriberArgs } from "@medusajs/medusa"
import { IUserModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const userModuleService: IUserModuleService =
container.resolve(ModuleRegistrationName.USER)
const users = await userModuleService.list()
}
import { createStep } from "@medusajs/workflows-sdk"
import { IUserModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
const step1 = createStep("step-1", async (_, context) => {
const userModuleService: IUserModuleService =
context.container.resolve(
ModuleRegistrationName.USER
)
const users = await userModuleService.list()
})
Was this section helpful?