Skip to content

add task solution#289

Open
ivan1302 wants to merge 4 commits into
mate-academy:masterfrom
ivan1302:develop
Open

add task solution#289
ivan1302 wants to merge 4 commits into
mate-academy:masterfrom
ivan1302:develop

Conversation

@ivan1302
Copy link
Copy Markdown

@ivan1302 ivan1302 commented Jun 2, 2026

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

This implementation has several critical blockers that must be fixed before approval. First, the ESLint configuration is broken - the .eslintrc.js file uses CommonJS syntax (module.exports) but package.json has "type": "module", causing the build to fail before tests can run. Rename .eslintrc.js to .eslintrc.cjs to fix this. Second, the User model is missing the isActive field - without this boolean flag, there's no way to track whether a user's account is activated, which is a core requirement for the activation flow. Third, login doesn't verify if the user is activated before allowing authentication - the requirements explicitly state that inactive accounts should be prompted to activate via email. Additionally, the activation endpoint should redirect to the profile page rather than returning JSON, and password validation rules should be enforced when updating passwords in the profile. These issues prevent the core authentication functionality from working as specified.


✨ 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 +55 to +66

if (password) {
if (password !== confirmationPassword) {
throw ApiError.BadRequest('Passwords do not match');
}
user.password = await bcrypt.hash(password, 10);
}

user.name = name || user.name;

await user.save();

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 requirements specify 'redirect to Profile after the activation'. Currently, the function only sends the user object back. A redirect response should be sent instead.

Comment on lines +55 to +60

if (password) {
if (password !== confirmationPassword) {
throw ApiError.BadRequest('Passwords do not match');
}
user.password = await bcrypt.hash(password, 10);
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 function exists for registration but is not used when updating the password in the profile. Passwords should be validated against the same rules (at least 6 characters).

Comment thread src/models/user.js
Comment on lines +29 to +30
type: DataTypes.DATE,
allowNull: 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 email service uses hardcoded port 3005 in activation and reset URLs (http://localhost:3005/...) while the main app runs on port 3000. Consider using process.env.PORT or a separate APP_URL environment variable for consistency.

Comment on lines +2 to +5

async function save(userId, refreshToken) {
const token = await Token.findOne({
where: { userId },
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 Token model defines only refreshToken field but the token service uses userId in queries. Sequelize may infer this from the belongsTo(User) association, but it's safer to explicitly define userId as a field in the Token model.

Comment on lines +2 to +6

async function save(userId, refreshToken) {
const token = await Token.findOne({
where: { userId },
});
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 access token expires in 35 seconds which is extremely short. This might cause frequent re-authentication in production. Consider using a longer duration like '1h' for practical use.

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

There is a critical blocker in src/controllers/auth.controller.js where the activate function clears the activationToken but never sets user.isActive = true. Since the login function checks if (!user.isActive) at lines 76-78, users will never be able to log in after clicking the activation link. This completely breaks the account activation flow and prevents users from ever accessing the system.

To fix: Add user.isActive = true; before await user.save(); in the activate function.

Additional issue: The checkResetToken endpoint returns the full user object including sensitive fields. Consider returning only a minimal success indicator or user ID instead of the entire entity.

The ESLint configuration error (.eslintrc.js incompatible with ES modules) and redirect behavior issues are non-blocking infrastructure concerns that don't affect core functionality.


✨ 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 +62 to +63

user.activationToken = null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CRITICAL BUG: The isActive flag is never set to true during activation. Users will remain inactive even after clicking the activation link, preventing them from ever logging in since the login function at line 76-78 checks if (!user.isActive). Set user.isActive = true; before saving.

user.resetTokenExpiry = null;

await user.save();
*/
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 checkResetToken endpoint returns the full user object including sensitive fields. Consider returning only a success indicator or minimal data instead of the entire user entity.

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 authentication system is well-implemented, and I'm approving it for educational purposes to help you progress while you continue learning. The critical activation blocker has been fixed - user.isActive = true is now properly set in the activate function. All core requirements are covered: registration with validation, email activation flow, login with inactive account check, password reset, and protected profile endpoints. Your middleware and error handling are solid. One quick fix needed: There's an ESLint configuration issue. Your package.json has "type": "module" (ES modules), but .eslintrc.js uses CommonJS syntax (module.exports). Simply rename the file: mv .eslintrc.js .eslintrc.cjs. This tells Node.js to treat the ESLint config as CommonJS, resolving the conflict. The .cjs extension forces CommonJS treatment even in an ES module project. Once you rename that file, your lint checks should pass. Keep up the good work on the authentication implementation!


✨ 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

Copy link
Copy Markdown

@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.

Good progress, but you need to pass all tests before requesting the review

Copy link
Copy Markdown

@Anton-Kuchmasov Anton-Kuchmasov left a comment

Choose a reason for hiding this comment

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

Good job!

Check out comments below - they might be helpful

Comment on lines +23 to +31
function validatePassword(value) {
if (!value) {
return 'Password is required';
}

if (value.length < 6) {
return 'At least 6 characters';
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

better approach is return true if all checks are passed

user.activationToken = null;
await user.save();

res.redirect('/profile');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I suggest making redirect on client side in this app

await tokenService.save(normalizedUser.id, refreshToken);

res.cookie('refreshToken', refreshToken, {
maxAge: 30 * 24 * 60 * 60 * 1000,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

good job!

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.

4 participants