feat: add public endpoint to resend user verification email by email address

This commit is contained in:
pradeepkumar
2026-04-08 10:32:35 +05:30
parent 9b4d64cf6a
commit b108eb35a2
2 changed files with 57 additions and 0 deletions

View File

@@ -620,6 +620,41 @@ export class AuthService {
};
}
// ==========================================
// RESEND VERIFICATION EMAIL BY EMAIL (PUBLIC)
// ==========================================
async resendVerificationByEmail(email: string) {
// Always return success to prevent email enumeration attacks
const successResponse = {
message: 'If an account with this email exists and is not yet verified, a verification email has been sent.',
};
const user = await this.prisma.user.findUnique({
where: { email: email.toLowerCase() },
include: {
userProfile: true,
agentProfile: true,
},
});
if (!user || user.emailVerified) {
return successResponse;
}
const profile = user.role === UserRole.AGENT ? user.agentProfile : user.userProfile;
// Emit event for email service to send verification
this.eventEmitter.emit('user.registered', {
userId: user.id,
email: user.email,
role: user.role,
firstName: profile?.firstName,
lastName: profile?.lastName,
});
return successResponse;
}
// ==========================================
// REFRESH TOKEN
// ==========================================