Skip to content

Conversation

aolamide
Copy link
Owner

@aolamide aolamide commented Sep 5, 2025

This pull request introduces a new email verification flow to the authentication module, including the API endpoint, service logic, DTO, and comprehensive tests. It also improves error handling for validation errors and refines the user entity to better support the verification process.

Email Verification Feature

  • Added a new PUT /auth/verify endpoint to AuthController that accepts a VerifyUserDto with a token, calls AuthService.verifyEmail, and returns a success response if the email is verified. [1] [2]
  • Implemented verifyEmail method in AuthService to validate the token, update user verification status, and handle invalid/expired tokens with a BadRequestException.
  • Added supporting methods to UserService for finding users by verification token and updating user records.
  • Updated User entity to allow emailVerifyToken and emailVerifySentAt to be nullable, reflecting their removal after verification.

Testing Enhancements

  • Added unit tests for the email verification endpoint in auth.controller.spec.ts and for the service logic in auth.service.spec.ts, covering both successful and error scenarios. [1] [2]

Error Handling Improvements

  • Enhanced HttpExceptionFilter to join validation error messages into a single string when a BadRequestException occurs, improving client-facing error responses. [1] [2]

@aolamide aolamide requested a review from Copilot September 5, 2025 12:22
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces a complete email verification feature to the authentication system, allowing users to verify their email addresses using tokens sent during registration.

  • Adds email verification endpoint with service logic to validate tokens and update user status
  • Enhances error handling in the HTTP exception filter to improve validation error messages
  • Updates user entity types to properly handle nullable verification fields after verification

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/modules/auth/auth.controller.ts Adds PUT /auth/verify endpoint for email verification
src/modules/auth/auth.service.ts Implements verifyEmail method with token validation and user update logic
src/modules/auth/dto/verify-user.dto.ts Creates DTO for email verification with token validation
src/modules/user/user.service.ts Adds methods to find users by verification token and update user records
src/modules/user/entities/user.entity.ts Updates entity to make verification fields nullable
src/modules/auth/auth.controller.spec.ts Adds comprehensive unit tests for verification endpoint
src/modules/auth/auth.service.spec.ts Adds unit tests for verification service logic
src/common/filters/http-exception.filter.ts Improves validation error message formatting

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +40 to 44
void this.notificationService.sendEmail(
createUserDto.email,
config.notification.email.templates.emailVerification,
{ name: createUserDto.name, token: emailVerificationToken },
);
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'void' operator to ignore the promise is unclear. Consider using '.catch()' to handle potential errors or add a comment explaining why errors are intentionally ignored.

Suggested change
void this.notificationService.sendEmail(
createUserDto.email,
config.notification.email.templates.emailVerification,
{ name: createUserDto.name, token: emailVerificationToken },
);
this.notificationService.sendEmail(
createUserDto.email,
config.notification.email.templates.emailVerification,
{ name: createUserDto.name, token: emailVerificationToken },
).catch((err) => {
// Log the error but do not interrupt registration flow
console.error('Failed to send verification email:', err);
});

Copilot uses AI. Check for mistakes.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors already logged in the send notification method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant