feat: implement secure email change workflow with verification token and event handling
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user