Skip to content

first try#238

Open
Eksonurit wants to merge 1 commit intomate-academy:masterfrom
Eksonurit:develop
Open

first try#238
Eksonurit wants to merge 1 commit intomate-academy:masterfrom
Eksonurit:develop

Conversation

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

This is a great start with a well-structured application. However, several core requirements are missing or broken, so I am requesting changes before this can be approved.

Here are the main issues to address:

  1. Missing Profile Management: The entire feature set for the profile page is missing. You need to implement the routes, controller logic, and services for authenticated users to change their name, password, and email as required by the task.
  2. Broken Account Activation: The activation flow is not working because the code incorrectly queries for a token field on the User model, but the model defines it as activationToken. This bug affects src/services/user.service.js and src/controllers/auth.controller.js and must be fixed for activation and login to work correctly.
  3. Incomplete Registration & User Model: The User model in src/models/user.js is missing the required name field. This needs to be added to the model and integrated into the registration logic in auth.controller.js and user.service.js.
  4. Missing 404 Handler: The server needs a catch-all middleware in src/index.js to handle requests to undefined routes and respond with a 404 status.

Please focus on implementing these missing features and fixing the activation bug. You're on the right track, and I look forward to your next submission!


✨ 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

};

const registration = 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 requires users to register with a name, email, and password. This implementation is missing the name field from the request body and the subsequent user creation logic.

return;
}

user.token = null;

Choose a reason for hiding this comment

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

The property on the User model is activationToken, not token. To nullify the token after activation, this should be user.activationToken = null;.

return res.sendStatus(401);
}

if (user.token) {

Choose a reason for hiding this comment

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

The check for an unactivated user is incorrect. The property on the User model is activationToken. This condition should be if (user.activationToken) to correctly check if the user needs to activate their email.

};

const resetPassword = async (req, res) => {
const { newPassword, resetToken } = 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 password reset process must include a password and a confirmation field, and you must verify they are equal. This implementation is missing the confirmation field and the associated validation.

allowedHeaders: ['Content-Type', 'Authorization'],
}),
);
app.use(authRouter);

Choose a reason for hiding this comment

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

The task requires a 404 response for any routes that are not defined. You should add a middleware function after your router to catch all unhandled requests and respond with a 404 status.

Comment on lines +4 to +21
export const User = client.define('users', {
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
password: {
type: DataTypes.STRING,
allowNull: false,
},
activationToken: {
type: DataTypes.STRING,
},
resetToken: {
type: DataTypes.STRING,
allowNull: true,
},
});

Choose a reason for hiding this comment

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

The task requirements specify that a user should be able to register with a name, email, and password, and later change their name on the profile page. This model is missing the name field required to store this information.

<a href="${href}">CLICK</a>
`;

return send({ email, subject: 'Activate', html });

Choose a reason for hiding this comment

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

The subject for the password reset email is 'Activate', which could be confusing for the user. It should be more descriptive, such as 'Reset Password'.

authRouter.post('/logout', authController.logout);
authRouter.post('/refresh', authController.refreshenToken);
authRouter.post('/forgot-password', authController.forgotPassword);
authRouter.post('/reset-password', authController.resetPassword);

Choose a reason for hiding this comment

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

The router is missing endpoints for the profile page functionality. According to the task description, authenticated users should be able to change their name, password, and email. You need to add routes to handle these actions.

}
}

async function addUser(email, password, activationToken = false) {

Choose a reason for hiding this comment

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

The task requires users to register with a name, email, and password. This function should also accept and save the user's name when a new user is created.

async function getUserByToken(token) {
const user = await User.findOne({
where: {
token,

Choose a reason for hiding this comment

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

The field in the User model is named activationToken, not token. This query should be where: { activationToken: token } to correctly find the user for account activation.

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