Local Notification Module Provider

The Local Notification Module Provider simulates sending a notification, but only logs the notification's details in the terminal. This is useful for development.

On Cloud, Medusa configures Medusa Emails, a managed email service, for the email channel by default, which is more suitable for production.

Development Only: Use the Local Notification Module Provider for the email channel only in local development, as explained in the Medusa Emails Cloud guide.

Register the Local Notification Module#

Note: The Local Notification Module Provider is registered by default in your application. It's configured to run on the feed channel.

Add the module into the providers array of the Notification Module:

Note: Only one provider can be defined for a channel.
medusa-config.ts
module.exports = defineConfig({
  // ...
  modules: [
    {
      resolve: "@medusajs/medusa/notification",
      options: {
        providers: [
          // ...
          {
            resolve: "@medusajs/medusa/notification-local",
            id: "local",
            options: {
              channels: ["email"],
            },
          },
        ],
      },
    },
  ],
})

Local Notification Module Options#

Option

Description

channels

The channels this notification module is used to send notifications for. While the local notification module doesn't actually send the notification, it's important to specify its channels to make sure it's used when a notification for that channel is created.


Send Notifications to the Admin Notification Panel#

The Local Notification Module Provider can also be used to send notifications to the Medusa Admin's notification panel. You can send notifications to the admin dashboard when a certain action occurs using a subscriber, a custom workflow or a workflow hook.

For example, to send an admin notification whenever an order is placed, create a subscriber at src/subscribers/order-placed.ts with the following content:

src/subscribers/order-placed.ts
import { Modules } from "@medusajs/framework/utils"

export default async function orderPlacedHandler({
  event: { data },
  container,
}: SubscriberArgs<{ id: string }>) {
  const notificationModuleService = container.resolve(Modules.NOTIFICATION)

  await notificationModuleService.createNotifications({
    to: "",
    channel: "feed",
    template: "admin-ui",
    data: {
      title: "New order",
      description: `A new order has been placed`,
    },
  })
}

export const config: SubscriberConfig = {
  event: "order.placed",
}

In this subscriber, you:

  • Resolve the Notification Module's main service from the Medusa container.
  • Use the createNotifications method of the Notification Module's main service to create a notification to be sent to the admin dashboard. By specifying the feed channel, the Local Notification Module Provider is used to send the notification.
  • The to property sets which admin users see the notification. Set it to an empty string to show the notification to all admin users, or to an admin user's ID to show it only to that user. Learn more in the Send Notifications to a Specific Admin User section.
  • The template property of the createNotifications method's parameter must be set to admin-ui.
  • The data property allows you to customize the content of the admin notification. It must contain title and description properties.
Warning: Medusa stores the data property of every notification, and the List Notifications and Get Notification API routes return it. Any admin user with the notification:read RBAC policy can view it, so don't pass data that those users shouldn't see.

Send Notifications to a Specific Admin User#

Note: Scoping feed notifications to a specific admin user is available since Medusa v2.23.0.

The List Notifications and Get Notification API routes only return a feed notification to an admin user if the notification's to property is either:

  • An empty string, which shows the notification to all admin users.
  • The ID of the authenticated admin user.

Notifications on other channels aren't affected by this scoping.

So, to show an admin notification to a single admin user, set the to property to that user's ID. For example:

Code
await notificationModuleService.createNotifications({
  to: userId,
  channel: "feed",
  template: "admin-ui",
  data: {
    title: "Export ready",
    description: "Your export is ready to download",
  },
})

Where userId is the ID of the admin user. In an API route, you can get the ID of the authenticated admin user from req.auth_context.actor_id.

Medusa's product import and export, order export, and inventory item export features use this to send their feed notifications only to the admin user who started the import or export. If you execute their workflows, such as exportProductsWorkflow or importProductsWorkflow, pass the admin user's ID in the workflow's to input. If you don't pass to, the notifications are shown to all admin users.

Test Sending Notification#

To test this out, start the Medusa application:

Then, place an order. The subscriber will run, sending a notification to the Medusa Admin's notification panel.

Was this page helpful?
Docs Assistant
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵