Fix/signup duplicate username#252
Conversation
✅ Deploy Preview for github-spy ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughBackend signup validation now checks both email and username uniqueness before user creation and gracefully handles MongoDB duplicate-key errors. Login redirects to root on success. Docker build stage installs full dependencies before copying remaining files. Includes test for username duplicate rejection. ChangesAuth validation and frontend build updates
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
spec/auth.routes.spec.cjs (1)
60-67: ⚡ Quick winAssert no DB side-effect on duplicate-username rejection.
This test checks status/message, but not that signup avoided creating an additional user record.
Proposed test hardening
it('should not sign up a user with existing username', async () => { await new User({ username: 'testuser', email: 'test@example.com', password: 'password123' }).save(); + const beforeCount = await User.countDocuments(); const res = await request(app) .post('/auth/signup') .send({ username: 'testuser', email: 'test2@example.com', password: 'password456' }); expect(res.status).toBe(400); expect(res.body.message).toBe('User already exists'); + const afterCount = await User.countDocuments(); + expect(afterCount).toBe(beforeCount); });🤖 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 `@spec/auth.routes.spec.cjs` around lines 60 - 67, The test "should not sign up a user with existing username" currently asserts status and message but not DB state; update it to verify no additional user record was created by checking the User collection after the POST (use the User model used in the test) — e.g., confirm User.countDocuments({ username: 'testuser' }) remains 1 or assert total users equals 1 and that no user exists with the second email — and keep the existing expectations (res.status and res.body.message) unchanged.
🤖 Prompt for all review comments with 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.
Nitpick comments:
In `@spec/auth.routes.spec.cjs`:
- Around line 60-67: The test "should not sign up a user with existing username"
currently asserts status and message but not DB state; update it to verify no
additional user record was created by checking the User collection after the
POST (use the User model used in the test) — e.g., confirm User.countDocuments({
username: 'testuser' }) remains 1 or assert total users equals 1 and that no
user exists with the second email — and keep the existing expectations
(res.status and res.body.message) unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: fc21ed71-577d-4ba5-95e6-0ab020c2176b
📒 Files selected for processing (4)
Dockerfile.prodbackend/routes/auth.jsspec/auth.routes.spec.cjssrc/pages/Login/Login.tsx
Related Issue
Closes: #251
Description
Handled duplicate username signup by checking both email and username before user creation and returning a consistent 400 response instead of a 500. Added a test to cover duplicate username registration.
How Has This Been Tested?
Type of Change
[x] Bug fix
[ ] New feature
[ ] Code style update
[ ] Breaking change
[ ] Documentation update
Summary by CodeRabbit
Improvements
Bug Fixes