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

@@ -282,6 +282,28 @@ export class AuthController {
return this.authService.resendVerificationEmail(userId); return this.authService.resendVerificationEmail(userId);
} }
// ==========================================
// RESEND VERIFICATION EMAIL BY EMAIL (PUBLIC)
// ==========================================
@Public()
@Post('resend-verification-public')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Resend verification email (public, by email)' })
@ApiBody({
schema: {
type: 'object',
properties: { email: { type: 'string', example: 'user@example.com' } },
required: ['email'],
},
})
@ApiResponse({ status: 200, description: 'If account exists, verification email sent' })
async resendVerificationPublic(@Body() body: { email: string }) {
if (!body?.email) {
return { message: 'Email is required' };
}
return this.authService.resendVerificationByEmail(body.email);
}
// ========================================== // ==========================================
// REFRESH TOKEN // REFRESH TOKEN
// ========================================== // ==========================================

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 // REFRESH TOKEN
// ========================================== // ==========================================