Skip to content

task#281

Open
Natalia2408-forever wants to merge 3 commits into
mate-academy:masterfrom
Natalia2408-forever:develop
Open

task#281
Natalia2408-forever wants to merge 3 commits into
mate-academy:masterfrom
Natalia2408-forever:develop

Conversation

@Natalia2408-forever
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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

The implementation has two critical bugs that will cause runtime failures. First, in src/services/user.service.js, the activation email is being called with an object sendActivationEmail({ email, activationToken }) but the email service expects two separate arguments: email as the first parameter and token as the second. This will cause the registration feature to fail. Second, there's a spelling error in multiple files (src/routes/auth.route.js, src/models/user.js, src/services/email.service.js, src/routes/user.route.js) where the route is written as /password-rest instead of /password-reset, which will cause 404 errors when the frontend tries to reach the password reset endpoint. Critical fixes required: 1. Change sendActivationEmail({ email, activationToken }) to sendActivationEmail(email, activationToken) in src/services/user.service.js 2. Fix the typo /password-rest/password-reset in all four files listed above. Minor improvements: - Add newEmailConfirmation field validation in updateEmail function (src/controllers/user.controller.js) to match the requirement that users must confirm their new email - Fix the typo in the response message: "exosts" → "exists" in src/controllers/auth.controller.js


✨ 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

Comment on lines +29 to +34
}

const user = await userService.findById(req.userId);
const isOldValid = await bcrypt.compare(oldPassword, user.password);

if (!isOldValid) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The activation email is being sent with an object { email, activationToken } as the first argument, but emailService.sendActivationEmail expects email as the first argument and token as the second. This will cause a runtime error and users won't receive activation emails.

Comment on lines +21 to +29
res.send(userService.normalize(user));
};

const updatePassword = async (req, res) => {
const { oldPassword, newPassword, confirmation } = req.body;

if (newPassword !== confirmation) {
throw ApiError.badRequest('New passwords do not match');
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The password validation only checks for minimum length (6 characters), but the requirements state that users should be 'informed about the rules for a password'. The validation errors should include comprehensive password rules that are communicated to users during registration.

Comment on lines +21 to +29
res.send(userService.normalize(user));
};

const updatePassword = async (req, res) => {
const { oldPassword, newPassword, confirmation } = req.body;

if (newPassword !== confirmation) {
throw ApiError.badRequest('New passwords do not match');
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The validatePassword function doesn't return a value when validation passes (it returns undefined implicitly). While this works for the current logic, it could be clearer to explicitly return null or a truthy value for consistency.

maxAge: 30 * 24 * 60 * 60 * 1000,
secure: true,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The updateEmail function only takes newEmail without requiring confirmation of the new email. According to the requirements, changing email should require 'confirm the new email', meaning users should type the new email twice to prevent typos.

Comment thread src/routes/auth.route.js
Comment on lines +17 to +20

authRouter.post(
'/password-rest',
catchError(authController.requestPasswordReset),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There's a typo in the route path: '/password-rest' should be '/password-reset' to be consistent with the naming convention used in the confirm endpoint ('/password-reset/confirm'). This mismatch will cause the password reset request endpoint to be unreachable.

Comment thread src/models/user.js
Comment on lines +17 to +19
},
activationToken: {
type: DataTypes.STRING,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The route is misspelled as '/password-rest' but should be '/password-reset' (with an 'e' before 't'). This typo will cause 404 errors when the frontend tries to request a password reset, as it would typically call '/password-reset'.

Comment on lines +17 to +19
subject,
html,
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The route path is '/password-rest' but should be '/password-reset' to match the task description and be consistent with the confirmation endpoint '/password-reset/confirm' on line 23.

Comment thread src/routes/user.route.js
Comment on lines +17 to +20
'/profile/password',
authMiddleware,
catchError(userController.updatePassword),
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The route path is /password-rest (typo: missing 'e' in 'reset') but the requirements and the confirm endpoint use /password-reset. This inconsistency could cause frontend-backend integration issues if the client expects the correct path /password-reset.

password: hashedPassword,
activationToken,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The sendActivationEmail is called with an object { email, activationToken } but the emailService.sendActivationEmail function expects two separate arguments: email as the first parameter and token as the second. This will cause a runtime error during user registration and prevent activation emails from being sent. Should be: emailService.sendActivationEmail(email, activationToken)

Copy link
Copy Markdown

@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

Your solution is approved. All critical bugs from previous reviews have been successfully resolved: the sendActivationEmail function is now called with two separate arguments (email, activationToken), the /password-reset route spelling is correct throughout, newEmailConfirmation validation is properly implemented in updateEmail, and the typo in auth.controller.js has been fixed. The codebase now correctly implements registration with activation email, login/logout, password reset, and profile management with all authenticated endpoints properly protected. All checklist requirements are met, including the 404 handler for unmapped routes. Great work on addressing all the issues thoroughly!


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

Footnotes

  1. Rate AI review example

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.

2 participants