feat: add email verification endpoints with token-based verification and SMTP integration

This commit is contained in:
JakkrapartXD 2026-01-30 14:53:50 +07:00
parent 9629f79c52
commit babccc4869
3 changed files with 153 additions and 2 deletions

View file

@ -8,7 +8,9 @@ import {
ProfileUpdateResponse,
ChangePasswordRequest,
ChangePasswordResponse,
updateAvatarResponse
updateAvatarResponse,
SendVerifyEmailResponse,
VerifyEmailResponse
} from '../types/user.types';
import { ChangePassword } from '../types/auth.types';
import { profileUpdateSchema, changePasswordSchema } from "../validators/user.validator";
@ -106,4 +108,34 @@ export class UserController {
return await this.userService.uploadAvatarPicture(token, file);
}
/**
* Send verification email to user
* @summary Send email verification link to authenticated user's email
* @param request Express request object with JWT token in Authorization header
*/
@Post('send-verify-email')
@Security('jwt')
@SuccessResponse('200', 'Verification email sent successfully')
@Response('401', 'Invalid or expired token')
@Response('400', 'Email already verified')
public async sendVerifyEmail(@Request() request: any): Promise<SendVerifyEmailResponse> {
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) throw new ValidationError('No token provided');
return await this.userService.sendVerifyEmail(token);
}
/**
* Verify email with token
* @summary Verify user's email address using verification token
* @param body Object containing the verification token
*/
@Post('verify-email')
@SuccessResponse('200', 'Email verified successfully')
@Response('401', 'Invalid or expired verification token')
@Response('400', 'Email already verified')
public async verifyEmail(@Body() body: { token: string }): Promise<VerifyEmailResponse> {
if (!body.token) throw new ValidationError('Verification token is required');
return await this.userService.verifyEmail(body.token);
}
}