Skip to content
Open
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
4 changes: 2 additions & 2 deletions backend/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ router.post("/signup", validateRequest(signupSchema), async (req, res) => {
});

if (existingUser)
return res.status(400).json({ message: 'User already exists' });
return res.status(400).json({ message: 'Username or email is invalid' });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Update downstream signup spec to match the new sanitized message contract.

The response contract changed at Line 19 and Line 26, but spec/auth.routes.spec.cjs (lines 71-88 in provided context) still expects "User already exists". This will cause test failures and leaves validation of the new security behavior incomplete.

Also applies to: 26-26

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/routes/auth.js` at line 19, Update the signup tests to match the new
sanitized error message returned by the signup handler: where the spec
(auth.routes.spec.cjs) asserts the old "User already exists" message, change
those expectations to the new "Username or email is invalid" string to match the
res.status(400).json response in the signup route handler in auth.js (the POST
/signup / signup handler that returns the sanitized error at the two call
sites). Ensure both assertions that expect the old message are updated so tests
validate the new contract.


const newUser = new User({ username, email, password });
await newUser.save();
res.status(201).json({ message: 'User created successfully' });
} catch (err) {
if (err && err.code === 11000) {
return res.status(400).json({ message: 'User already exists' });
return res.status(400).json({ message: 'Username or email is invalid' });
}

res.status(500).json({ message: 'Error creating user', error: err.message });
Expand Down
Loading