React to a new signup with `UserRegisteredEvent`
Create your AppUser, link a referral, queue a welcome email — all in one listener.
The canonical extension. The signup payload is open-ended ([key: string]: any), so any field your frontend sends — firstName, referralCode, marketingSource — is on the event payload.
The listener
Register it
Make sure EventEmitterModule.forRoot() is in AppModule imports — without it, no listener fires.
Idempotency
If the signup transaction succeeds but a downstream step fails and the user retries, the listener may run twice. Make the AppUser save idempotent:
Alternative: put a unique constraint on authUserId and let the DB reject duplicates.
Want the welcome email immediately, not via queue?
Move the send call into the listener directly:
But know the trade-off: a slow email provider now delays the signup response. Most apps prefer the queue.
Related
- User Model — the
NestAuthUser↔AppUserpattern. - Events & Hooks.
- Sending Emails.