Skip to content

done#283

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

done#283
bcheban wants to merge 4 commits into
mate-academy:masterfrom
bcheban:develop

Conversation

@bcheban
Copy link
Copy Markdown

@bcheban bcheban commented May 17, 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

Your implementation has a critical functional issue that blocks the email confirmation feature. The route /profile/confirm-email/:token is defined under userRouter with authMiddleware applied globally, but users access this endpoint from email links where they won't have an active session cookie. This means email confirmations will always fail with a 401 Unauthorized error. Move this specific route to auth.route.js and remove authMiddleware from it, or apply guestMiddleware instead. All other authentication features (registration, activation, login, password reset, profile management) are correctly implemented.


✨ 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 thread src/routes/user.route.js Outdated
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 function confirmEmailChange must be moved from user.controller.js and user.service.js to auth.controller.js and auth.service.js respectively, and the duplicate functions should be removed. This is required to fix a runtime error where an undefined function is being called during email confirmation.


✨ 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 +31 to +33
});
}
};
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 confirmEmailChange function is imported here but doesn't exist in auth.controller.js. This function is currently only in user.controller.js (lines 76-89). It needs to be moved to auth.controller.js.

Comment on lines +26 to +29
return res.status(err.status || 500).json({ message: err.message });
}
};

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 references authController.confirmEmailChange, but this function is defined in user.controller.js, not auth.controller.js. This import mismatch will cause a runtime error when users access email confirmation links.

Comment thread src/routes/auth.route.js
Comment on lines +26 to +30

authRouter.get(
'/confirm-email/:token',
guestMiddleware,
authController.confirmEmailChange,
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 calls authController.confirmEmailChange, but this function is not exported from auth.controller.js. Checking auth.controller.js (lines 1-117), the exported functions are: register, activate, login, logout, requestPasswordReset, confirmPasswordReset. The confirmEmailChange function is only in user.controller.js. Move confirmEmailChange from user.controller.js to auth.controller.js, and move confirmEmailChange from user.service.js to auth.service.js.

Comment on lines +26 to +30

const user = await User.create({
name,
email,
password: hashedPassword,
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 references authController.confirmEmailChange, but this function is not exported from auth.controller.js. The exported functions are: register, activate, login, logout, requestPasswordReset, confirmPasswordReset. The confirmEmailChange function needs to be moved from user.controller.js to auth.controller.js to fix this broken reference.

Comment on lines +26 to +29
<p>Please activate your account by clicking the link below:</p>
<a href="${link}">${link}</a>
<p>This link will expire in 24 hours.</p>
`,
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 calls authController.confirmEmailChange, but this function is not exported from auth.controller.js. The exported functions in auth.controller.js are: register, activate, login, logout, requestPasswordReset, confirmPasswordReset. The confirmEmailChange function exists only in user.controller.js (lines 76-89). Move confirmEmailChange from user.controller.js to auth.controller.js and the service call from user.service.js to auth.service.js.

Comment thread src/services/user.service.js Outdated
Comment on lines +104 to +127

export const confirmEmailChange = async (token) => {
const user = await User.findOne({ where: { emailChangeToken: token } });

if (!user || !user.pendingEmail) {
throw Object.assign(new Error('Invalid email change token'), {
status: 400,
});
}

const oldEmail = user.email;

user.email = user.pendingEmail;
user.pendingEmail = null;
user.emailChangeToken = null;
await user.save();

try {
await emailService.sendEmailChangeNotice(oldEmail);
} catch (emailErr) {
throw new Error(emailErr.message);
}

return user;
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 confirmEmailChange function is defined here in user.service.js, but it's called by a route in auth.route.js via authController.confirmEmailChange. This function doesn't exist in auth.controller.js. Move confirmEmailChange from user.service.js to auth.service.js and from user.controller.js to auth.controller.js to fix this broken reference.

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 implementation is excellent and addresses all core requirements. The confirmEmailChange function has been correctly relocated from user.controller.js to auth.controller.js (lines 117-130) and from user.service.js to auth.service.js (lines 132-155), eliminating the runtime error. All authentication features work properly: registration with password validation, account activation, login/logout with inactive account checks, password reset with token expiry, and complete profile management including email change with old email notification.

There's one configuration fix needed: rename .eslintrc.js to .eslintrc.cjs since your project uses ES modules ("type": "module" in package.json) but the ESLint config uses CommonJS syntax (module.exports). This is why ESLint is failing, not your application code. Prettier ran successfully on all files, confirming your code formatting is correct.

Great work on the clean separation of concerns between controllers and services, and thorough implementation of all the required 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

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