feat: implement secure email change workflow with verification token and event handling

This commit is contained in:
pradeepkumar
2026-04-20 14:07:41 +05:30
parent 37df1f49d4
commit 1541dba6e9
5 changed files with 171 additions and 0 deletions

View File

@@ -99,4 +99,26 @@ export class EmailListener {
this.logger.error(`Failed to send welcome email to ${payload.email}:`, error);
}
}
@OnEvent('user.email-change-requested')
async handleEmailChangeRequested(payload: {
newEmail: string;
token: string;
name?: string;
}) {
this.logger.log(`Email change requested for: ${payload.newEmail}`);
try {
await this.emailService.sendVerificationEmail(
payload.newEmail,
payload.token,
payload.name,
);
this.logger.log(`Email-change verification sent to: ${payload.newEmail}`);
} catch (error) {
this.logger.error(
`Failed to send email-change verification to ${payload.newEmail}:`,
error,
);
}
}
}