Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Medusa Development Resources: Issue in Customers in Storefront - Medusa Development Resources #10127

Open
1 of 2 tasks
omesh845 opened this issue Nov 17, 2024 · 1 comment
Open
1 of 2 tasks

Comments

@omesh845
Copy link

omesh845 commented Nov 17, 2024

What Medusa version and documentation are you using?

v2

Preliminary Checks

Issue Summary

Bug Report: customer.created Subscriber Not Triggering

Description

I've created a subscriber to trigger when a new customer is created using the customer.created event. It works fine when customers are created through the admin dashboard but does not trigger when customers are created via the API (Storefront).

In contrast, another subscriber I implemented for the order.placed event works as expected for all scenarios.

Code Examples

Here is the code for the customer.created subscriber:

import type { SubscriberArgs, SubscriberConfig } from "@medusajs/medusa";
import { Modules } from "@medusajs/utils";

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

  const customer = await customerModuleService.retrieveCustomer(data.id);

  // Your email sending logic here
  console.log(`Customer created: ${customer.email}`);
}

export const config: SubscriberConfig = {
  event: "customer.created",
};

Expected Behavior

The customer.created event should trigger the subscriber when a customer is created via:

  1. The admin dashboard.
  2. The Storefront API.

Actual Behavior

The event only triggers when a customer is created using the admin dashboard. When creating a customer via the Storefront API:

  • The customer is created successfully.
  • Tokens are returned correctly.
  • The event is not triggered, and the subscriber does not run.

Steps to Reproduce

  1. Implement the above customer.created subscriber in subscribers/test-sub.ts.
  2. Create a customer using the admin dashboard → Event triggers correctly.
  3. Create a customer via the Storefront API → Event does not trigger.

Additional Information

The following subscriber for order.placed works as expected in all scenarios:

import { Modules } from "@medusajs/utils";
import { INotificationModuleService, IOrderModuleService } from "@medusajs/types";
import { SubscriberArgs, SubscriberConfig } from "@medusajs/medusa";
import { EmailTemplates } from "../modules/email-notifications/templates";

export default async function orderPlacedHandler({
  event: { data },
  container,
}: SubscriberArgs<any>) {
  const notificationModuleService: INotificationModuleService = container.resolve(Modules.NOTIFICATION);
  const orderModuleService: IOrderModuleService = container.resolve(Modules.ORDER);

  const order = await orderModuleService.retrieveOrder(data.id, {
    relations: ["items", "summary", "shipping_address"],
  });
  const shippingAddress = await (orderModuleService as any).orderAddressService_.retrieve(order.shipping_address.id);

  try {
    await notificationModuleService.createNotifications({
      to: order.email,
      channel: "email",
      template: EmailTemplates.ORDER_PLACED,
      data: {
        emailOptions: {
          replyTo: "[email protected]",
          subject: "Your order has been placed",
        },
        order,
        shippingAddress,
        preview: "Thank you for your order!",
      },
    });
  } catch (error) {
    console.error("Error sending order confirmation notification:", error);
  }
}

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

Questions

  1. Is there a difference in how the customer.created event is emitted for the admin dashboard vs. Storefront API?
  2. Am I missing any configuration for the subscriber to work with the Storefront API?

Environment

  • MedusaJS version: v2
  • Node.js version: v22.9.0
  • Storefront: Expo

How can this issue be resolved?

  1. Ensure the Event is Emitted Correctly for customer.created via Stormfront API
  2. if I'm Missing Something, please let me know

Are you interested in working on this issue?

  • I would like to fix this issue
@tadinski
Copy link

experiencing same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants