Skip to content

Conversation

@Vitalii120296
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

You've set up a good structure for the application, but several critical requirements are missing, and there are some significant security issues that need to be addressed. I am requesting changes to align the project with the task description.

Here are the key areas to focus on:

  • Missing Validations: The registration process is missing the name field. The password reset and profile update features (for both password and email) are missing the required confirmation field checks.
  • Security: User-specific routes in user.route.js incorrectly use an email from the URL to identify the user. This is a major security risk; you must use the user's identity from the validated authentication token instead. Similarly, the changeData function in user.service.js allows updating any field, which should be restricted to only safe fields like name.
  • Core Functionality: The application is missing the required 404 error handler for undefined routes. Also, the email service has an incorrect transporter configuration that will prevent emails from being sent.

Please address these points to ensure the application is secure and fully functional according to the requirements.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example


res.cookie('refreshToken', refreshToken, {
maxAge: 30 * 24 * 60 * 60 * 1000,
HttpOnly: true,

Choose a reason for hiding this comment

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

The property name for setting an HTTP-only cookie is case-sensitive and should be camel-cased. Please change HttpOnly to httpOnly to ensure the cookie is properly secured against client-side script access.

import { tokenConfig } from '../config/token.config.js';

const register = async (req, res) => {
const { email, password } = req.body;

Choose a reason for hiding this comment

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

The task requirements state that registration should use name, email, and password. The name field is missing from the request body handling and the user creation logic.


const resetPassword = async (req, res) => {
const { email, resetToken } = req.params;
const { password } = req.body;

Choose a reason for hiding this comment

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

The requirements specify that the reset password confirmation should have password and confirmation fields that must be equal. The backend should validate this, but currently, it only accepts the password and doesn't perform the confirmation check.


const changePassword = async (req, res) => {
const { email } = req.params;
const { oldPassword, newPassword } = req.body;

Choose a reason for hiding this comment

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

The task requires that changing a password should include an old one, new password, and confirmation. This implementation is missing the confirmation field from the request body and the logic to verify that newPassword matches it.


const changeEmail = async (req, res) => {
const { email } = req.params;
const { password, newEmail } = req.body;

Choose a reason for hiding this comment

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

According to the requirements, the user must "confirm the new email". This suggests that the request body should also include a confirmation field for the new email, and you should validate that it matches newEmail. This check is currently missing.

auth: {
type: 'OAuth2',
user: 'v.hulaievych@gmail.com',
emailConfig,

Choose a reason for hiding this comment

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

The nodemailer transporter's auth object for OAuth2 does not have a property named emailConfig. You should spread the properties from your emailConfig object directly into the auth object like this: ...emailConfig.

Comment on lines 71 to 73
} catch (error) {
console.error('Error sending email:', error.message);
}

Choose a reason for hiding this comment

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

This catch block only logs the error but doesn't re-throw it. This means if sending the email fails, the API route will still return a success status, and the user will never receive their password reset link. The error should be propagated up, similar to how you handle it in sendActivationEmail.


try {
await send({ email, subject, html });
console.log('✅ Reset password email sent to', email);

Choose a reason for hiding this comment

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

This log message seems to be a copy-paste from the sendResetPasswordEmail function. It should be updated to accurately reflect that an email change notification was sent.

Comment on lines 85 to 87
} catch (error) {
console.error('Error sending email:', error.message);
}

Choose a reason for hiding this comment

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

Similar to the password reset function, this catch block swallows the error. If the notification email fails to send, the error should be re-thrown so the application can handle it appropriately instead of silently failing.

id: data.id,
},
data: {
...data,

Choose a reason for hiding this comment

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

This is a major security risk. Spreading the data object directly from the request body into the update query allows a user to change any field in their user record, including potentially id, password, or activationToken. The task requirement is to allow changing the user's name. This function should be updated to only allow specific fields (like name) to be changed.

Copy link

@brespect brespect left a comment

Choose a reason for hiding this comment

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

Well done!

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.

3 participants