Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/http-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { prismaClient } from "@repo/db/client";
import { NodeRegistry } from "@repo/nodes/nodeClinet";
import express from "express";
import { userRouter } from "./routes/userRoutes/userRoutes.js";
const app = express()
// const main = async () => {
// try {
Expand All @@ -16,6 +17,8 @@ const app = express()
// main().then(() => {
// console.log("This log is from http Backend");
// });

app.use("/user" , userRouter)
const PORT= 3000
async function startServer() {
await NodeRegistry.registerAll()
Expand Down
30 changes: 30 additions & 0 deletions apps/http-backend/src/routes/userRoutes/userRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { prismaClient } from "@repo/db";
import { Express, Router } from "express";

const router : Router = Router();

router.post("/create" , async (req , res) =>{

// const Data = req.body;

// const {name , email , password} = req.body
// console.log(Data)
try {
const user = await prismaClient.user.create({
data : {
name : "name",
email : "email",
password : "password"
}
})
Comment on lines +13 to +19

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Replace hardcoded values and hash passwords before storage.

This endpoint has multiple critical issues:

  1. Hardcoded email: Using "email" as a hardcoded value will cause a unique constraint violation on the second request if the email field has a unique constraint in your database schema.
  2. Plain text password: Storing passwords in plain text is a critical security vulnerability. Passwords must be hashed using a library like bcrypt or argon2.
  3. Commented code: Lines 8-11 suggest the intent to parse req.body, but the implementation uses hardcoded values instead.

Apply this diff to use request body data and hash passwords:

+import bcrypt from 'bcrypt';
+
 const router : Router = Router();
 
 router.post("/create" , async (req  , res) =>{
 
-    // const Data = req.body;
-    
-    // const {name , email , password} = req.body
-    // console.log(Data)
+    const {name , email , password} = req.body;
+    
+    if (!name || !email || !password) {
+        return res.status(400).json({ message: "Missing required fields" });
+    }
+    
     try {
+        const hashedPassword = await bcrypt.hash(password, 10);
         const user = await prismaClient.user.create({
             data : {
-                name : "name",
-                email : "email",
-                password : "password"
+                name,
+                email,
+                password: hashedPassword
             }
         })
-        res.json({
-            message : "Signup DOne",
+        res.status(201).json({
+            message : "Signup Done",
             user
         })
     }

Note: Ensure express.json() middleware is configured in index.ts to parse the request body.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In apps/http-backend/src/routes/userRoutes/userRoutes.ts around lines 13 to 19,
the handler is creating a user with hardcoded name/email/password and storing
the password in plain text; replace the hardcoded values with data parsed from
req.body (e.g., name, email, password), validate required fields and email
format, hash the password with a secure library like bcrypt or argon2 (await the
hash) before calling prismaClient.user.create, and handle unique constraint /
validation errors by returning appropriate HTTP responses; also ensure
express.json() is enabled in index.ts so req.body is populated.

res.json({
message : "Signup DOne",
user
})
}
catch(e){
console.log("Detailed Error" , e)
}
Comment on lines +25 to +27

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Send error response to client.

The catch block logs the error but does not send a response, causing the client to hang indefinitely.

Apply this diff:

   catch(e){
     console.log("Detailed Error" , e)
+    res.status(500).json({ message: "Internal server error" })
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
catch(e){
console.log("Detailed Error" , e)
}
catch(e){
console.log("Detailed Error" , e)
res.status(500).json({ message: "Internal server error" })
}
🤖 Prompt for AI Agents
In apps/http-backend/src/routes/userRoutes/userRoutes.ts around lines 25 to 27,
the catch block only logs the error and never sends a response, causing the
client to hang; update the catch to send an HTTP error response (e.g.,
res.status(500).json({ error: "Internal Server Error", details: e?.message }))
so the client receives a failure status and message, and keep or enhance the
existing logging as needed for debugging.

})
Comment on lines +6 to +28

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the full userRoutes.ts file to understand context
cat -n apps/http-backend/src/routes/userRoutes/userRoutes.ts

Repository: Dev-Pross/BuildFlow

Length of output: 947


🏁 Script executed:

# Check if zod or joi is already in dependencies
cat apps/http-backend/package.json | grep -A 50 '"dependencies"'

Repository: Dev-Pross/BuildFlow

Length of output: 233


🏁 Script executed:

# Search for UUID-related logic in the codebase to verify PR title accuracy
rg -i "uuid" --type ts --type js -n

Repository: Dev-Pross/BuildFlow

Length of output: 45


🏁 Script executed:

# Look for other user creation or validation logic
rg -n "prismaClient.user.create"

Repository: Dev-Pross/BuildFlow

Length of output: 173


🏁 Script executed:

# Check PR metadata to verify title and description
gh pr view --json title,body,files

Repository: Dev-Pross/BuildFlow

Length of output: 135


🏁 Script executed:

# Search entire repo for UUID-related logic across all packages
rg -i "uuid" -n --max-count 20

Repository: Dev-Pross/BuildFlow

Length of output: 936


Add input validation and verify PR scope alignment.

The endpoint contains hardcoded credential strings instead of using request body values, and lacks email/password validation. Additionally, the PR title "UUID issue fixed" appears misaligned with this endpoint's changes—UUIDs in the codebase are handled automatically via Prisma's @default(uuid()) in the schema, not through application logic.

Required fixes:

  1. Use destructured values from req.body instead of hardcoded strings
  2. Add input validation for email format and password requirements (consider zod or joi—neither is currently in dependencies)
  3. Clarify the PR's scope: confirm whether this PR targets the UUID schema setup or these endpoint validations, or if multiple issues are being conflated

Example validation approach:

import { z } from 'zod';

const createUserSchema = z.object({
  name: z.string().min(1),
  email: z.string().email(),
  password: z.string().min(8)
});

const validationResult = createUserSchema.safeParse(req.body);
if (!validationResult.success) {
  return res.status(400).json({ message: "Invalid input", errors: validationResult.error });
}

const { name, email, password } = validationResult.data;
// use these in create()
🤖 Prompt for AI Agents
In apps/http-backend/src/routes/userRoutes/userRoutes.ts around lines 6 to 28,
the POST /create handler currently uses hardcoded credential strings and lacks
input validation; replace those hardcoded values by destructuring name, email,
password from req.body and pass them into prismaClient.user.create, validate
inputs before creating the user (if zod is available add a zod schema that
enforces non-empty name, email format, and password length; if zod isn't in
dependencies perform equivalent manual checks and return res.status(400).json({
message: "Invalid input", errors: [...] }) on failure), and ensure errors are
handled by sending an appropriate HTTP response (400 on validation errors, 500
on unexpected exceptions) instead of only console.log; finally, confirm whether
this PR is meant to address UUID schema changes or endpoint validation and
update the PR title/description to match the actual changes.


export const userRouter = router ;
2 changes: 1 addition & 1 deletion apps/http-backend/tsconfig.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":["./src/index.ts","./src/routes/nodes.routes.ts"],"version":"5.7.3"}
{"root":["./src/index.ts","./src/routes/nodes.routes.ts","./src/routes/userRoutes/userRoutes.ts"],"version":"5.7.3"}