-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add email verification functionality #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
| void this.notificationService.sendEmail( | ||
| createUserDto.email, | ||
| config.notification.email.templates.emailVerification, | ||
| { name: createUserDto.name, token: emailVerificationToken }, | ||
| ); |
Copilot
AI
Sep 5, 2025
There was a problem hiding this comment.
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.
| 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.
There was a problem hiding this comment.
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
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
PUT /auth/verifyendpoint toAuthControllerthat accepts aVerifyUserDtowith a token, callsAuthService.verifyEmail, and returns a success response if the email is verified. [1] [2]verifyEmailmethod inAuthServiceto validate the token, update user verification status, and handle invalid/expired tokens with aBadRequestException.UserServicefor finding users by verification token and updating user records.Userentity to allowemailVerifyTokenandemailVerifySentAtto be nullable, reflecting their removal after verification.Testing Enhancements
auth.controller.spec.tsand for the service logic inauth.service.spec.ts, covering both successful and error scenarios. [1] [2]Error Handling Improvements
HttpExceptionFilterto join validation error messages into a single string when aBadRequestExceptionoccurs, improving client-facing error responses. [1] [2]