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

[Feature]: Implement EventBus and emit an event when the OTP is generated #2

Open
adevinwild opened this issue Feb 16, 2025 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@adevinwild
Copy link
Member

Is your feature request related to a problem?

A key feature of the plugin is to be able to emit an event when an OTP code is generated so that developers using the plugin can create a Subscriber, allowing them to distribute the codes to their users.

Describe the solution you'd like

There are 3 points to manage during this implementation

Initialize the EventBus module in the constructor

The first will be to add the event bus interface in the InjectedDependencies type at the main service level and initialize it in the constructor

import { IEventBusModuleService } from "@medusajs/framework/types"

type InjectedDependencies = {
 // ... rest
 [Modules.EVENT_BUS]: IEventBusModuleService // ✅ This is the right interface we need to use
}

Emit an event at the right place

Once everything is OK with the initialization, we need to make sure that we can emit the event, but before that, I thought it would be interesting to export a variable that could improve the DX, so that developers don't have to manage the event names manually? Something like exporting a constant that will contain all the events names (for now there is only one planned of course)

import { Events } from '@perseidesjs/auth-otp`

And could be used in a subscriber config like this :

// src/subscribers/otp-generated.ts
import { Events } from '@perseidesjs/auth-otp`

// ... subscriber logic

export const config: SubscriberConfig = {
  event: Events.OTP_GENERATED // ℹ️ This is the event submitted when the OTP is generated from the OTP provider
}

Would love a feedback on this, or should we keep it simple and stupid and just put the name of the event in the docs ? 🤔
For the event emission part, we'll simply need to trigger the event following the OTP caching logic, "using the correct syntax"

Update the docs

It may seem trivial, but it's crucial to provide a brief example of usage along with the available parameters sent by the event. The identifier and the OTP are the key pieces of data in this context

Describe alternatives you've considered

No response

Priority

Critical

Additional context

No response

@adevinwild adevinwild added enhancement New feature or request good first issue Good for newcomers labels Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant