Skip to content

Conversation

@StanislavKapytsia
Copy link

For start this thing:

🚀 1. Clone the repository
git clone <URL_твоего_репо>
cd NODE_AUTH-APP

🔧 2. Install dependencies
npm install

🔐 3. Create a .env file
Copy the example:
cp .env-example .env

Fill in the environment variables:

  • DATABASE_URL — database connection string
  • JWT_ACCESS_SECRET
  • JWT_REFRESH_SECRET
  • SMTP_HOST, SMTP_USER, SMTP_PASS
  • other variables you use

4.🗄️ Apply Prisma migrations
If the database is empty:
npx prisma migrate deploy

If you want to create a new migration (not required for running):
npx prisma migrate dev

🧪 5. (Optional) Generate Prisma Client
npx prisma generate

This usually happens automatically when you run npm install, but you can do it manually.

▶️ 6. Run the application
npm run dev
or
npm start

📂 Project structure (briefly)
src/
controllers/
routes/
services/
utils/
middleware/
prisma/
schema.prisma
migrations/

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, and the overall structure of your application is well-organized. However, several critical issues are currently breaking core functionality and preventing the project from meeting all requirements. I am requesting changes to address these blockers.

Here are the most important issues to fix:

  1. Critical Security Flaw: The authentication middleware in src/midlleware/auth.middleware.js validates the token but doesn't attach the decoded user to the request object (e.g., req.user = userData). This prevents downstream routes from knowing who the authenticated user is, making authorization impossible.
  2. Broken Functionality: There are several runtime errors. For example, you call a non-existent function userService.findBy in src/controllers/auth.controller.js and src/controllers/reset.controller.js. There are also typos in import paths, such as in src/routes/user.router.js, which will cause the server to crash.
  3. Missing Requirements: The login controller in src/controllers/auth.controller.js doesn't check if a user's account has been activated before allowing them to log in. Additionally, your src/index.js is missing a catch-all route to handle 404 errors for undefined pages.

Please address these points, and I'll be happy to take another look!


✨ 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

);

-- CreateTable
CREATE TABLE "users" (

Choose a reason for hiding this comment

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

The users table is missing a column to store the user's name, which is a required field for registration according to the task description.

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "tokens" ADD COLUMN "resetInterval" TIMESTAMPTZ(6);

Choose a reason for hiding this comment

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

The SQL statement is correct, but the migration's filename (add_userid) doesn't match the action performed (adding resetInterval). It's a good practice to name migrations descriptively to make the database history easier to understand.

Comment on lines +1 to +2
-- AlterTable
ALTER TABLE "users" ADD COLUMN "tokenActivationExpires" TIMESTAMPTZ(6);

Choose a reason for hiding this comment

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

The migration filename add is not descriptive. It's a good practice to name migration files based on the changes they introduce, for example, add_token_activation_expires_to_users. This makes it easier to understand the evolution of the database schema at a glance.

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "reset_tokens" ADD COLUMN "resetInterval" TIMESTAMPTZ(6);

Choose a reason for hiding this comment

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

The SQL is correct, but the migration filename add is too generic. It's a best practice to name migrations descriptively to clearly state what change is being made, which helps with maintaining the project long-term.

@@ -0,0 +1,14 @@
import { Router } from 'express';
import { userController } from '../controllers/user.controller.js';
import { authMiddleware } from '../midlleware/auth.middleware.js';

Choose a reason for hiding this comment

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

There appears to be a typo in the import path. The directory is likely intended to be middleware, but it is spelled as midlleware. This will cause the import to fail and the server to crash.

Comment on lines 25 to 40
async function deleteByUserId(userId) {
const token = await db.token.findFirst({
where: {
userId,
},
});

if (!token) {
return null;
}

return db.token.delete({
where: {
userId,
},
});

Choose a reason for hiding this comment

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

The current implementation uses a findFirst followed by a delete. This is not an atomic operation and creates a potential race condition. If the token is deleted by another request between the find and delete calls, the delete operation will throw an unhandled error. Using a single deleteMany operation would be more robust as it is atomic and does not throw an error if no record is found.

import 'dotenv/config';

// eslint-disable-next-line no-console
console.log(process.env.SMTP_USER, process.env.SMTP_PASSWORD);

Choose a reason for hiding this comment

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

Logging environment variables, especially potential secrets like a user and password, is a security risk and should be avoided in production code. This line should be removed.

Comment on lines 13 to 16
auth: {
user: testAccount.user,
pass: testAccount.pass,
},

Choose a reason for hiding this comment

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

The transporter is currently configured to create and use a new temporary test account on every call. This ignores the SMTP_USER and SMTP_PASSWORD environment variables. To allow for configuration with a real email service, the auth object should be updated to use the environment variables from process.env.

Comment on lines 83 to 84
function normalize({ id, email }) {
return { id, email };

Choose a reason for hiding this comment

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

The normalize function only returns the user's id and email. The task involves managing a user profile that includes a name. It's a good practice to include the userName in the normalized user object that is sent to the client upon successful authentication. This avoids the need for the frontend to make a separate API call just to get the user's name for display.

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

Excellent work on this project! Your implementation is solid, secure, and meets all the functional requirements. You've successfully addressed all the feedback from the previous review, and the authentication, password reset, and profile management flows are all working perfectly. I am approving your solution.

Please note that the build is currently failing due to an ESLint configuration issue, not a problem with your code logic. To fix this, you'll need to rename the .eslintrc.js file in your project's root to .eslintrc.cjs. This will resolve the conflict between ES Modules and CommonJS syntax. Great job overall!


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

Footnotes

  1. Rate AI review example

Comment on lines +13 to +22
CREATE TABLE "users" (
"id" SERIAL NOT NULL,
"email" VARCHAR(255) NOT NULL,
"password" VARCHAR(255) NOT NULL,
"activationToken" VARCHAR(255),
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(6) NOT NULL,

CONSTRAINT "users_pkey" PRIMARY KEY ("id")
);

Choose a reason for hiding this comment

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

The requirements state that registration should include a name, but this table definition is missing a column to store it (e.g., user_name or userName).

Comment on lines +84 to +86
return res.status(204).send({
message: 'No Content',
});

Choose a reason for hiding this comment

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

According to the HTTP specification, a 204 No Content response must not contain a message body. It's better to use res.sendStatus(204) or res.status(204).send() to send an empty response in this case.

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