Skip to content

feat: add username field to signup validation schema - #24

Merged
yash-pouranik merged 4 commits into
geturbackend:mainfrom
svilupp0:feat/add-username-signup
Jan 28, 2026
Merged

feat: add username field to signup validation schema#24
yash-pouranik merged 4 commits into
geturbackend:mainfrom
svilupp0:feat/add-username-signup

Conversation

@svilupp0

@svilupp0 svilupp0 commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

Closes #14

Changes

  • Added signupSchema to backend/utils/input.validation.js with username validation (min 3 characters)
  • Updated userAuth.controller.js to use signupSchema and save username during signup

Testing

  • Username field is now validated and stored during user registration

Summary by CodeRabbit

  • New Features
    • Enhanced user registration validation: username (3–30 chars), email format (max 100 chars), password (6–100 chars).
    • Registration flow now collects and stores a username as part of signup and ignores unexpected extra fields to ensure clean user data.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel

vercel Bot commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

@svilupp0 is attempting to deploy a commit to the Yash Pouranik's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jan 27, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Added a required username field (3–30 chars) to signup input validation and updated the signup controller to parse and include username when constructing the new user record.

Changes

Cohort / File(s) Summary
Signup Validation Schema
backend/utils/input.validation.js
Added exported signupSchema validating username (3–30 chars), email (required, valid format, max 100 chars), and password (6–100 chars).
Signup Controller Logic
backend/controllers/userAuth.controller.js
Switched signup parsing to signupSchema.parse(req.body), extracting username, email, password; added username to newUser and removed spreading of otherData.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibble at keys, a username in sight,
Three chars to shine in the signup light.
Email and password hop in the queue,
Together we build an account that's new. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a username field to the signup validation schema, which matches the primary objective of the PR.
Linked Issues check ✅ Passed All requirements from issue #14 are met: signupSchema added with username validation (3+ characters), userAuth.controller.js updated to use the schema and persist username during registration.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue #14. The modifications to input validation and the controller are scoped to implementing username field support in the signup flow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/controllers/userAuth.controller.js (1)

16-19: Clarify the role of username in your application design.

Username uniqueness is not enforced—the code accepts and stores usernames but neither checks for duplicates nor uses them for authentication (login uses email only). If usernames should be unique identifiers, add a uniqueness check in the signup handler and consider adding a database index. If usernames are meant as display names only, document this design intent to avoid future confusion.

🤖 Fix all issues with AI agents
In `@backend/controllers/userAuth.controller.js`:
- Line 4: The controller references z.ZodError in the login and signup handlers
but never imports z, causing a ReferenceError on validation failures; add the
Zod import (e.g. const { z } = require('zod');) near the top of
userAuth.controller.js alongside the existing import of loginSchema and
signupSchema so that the z.ZodError checks in the functions (where z.ZodError is
used) work and validation errors return the intended 400 responses.
🧹 Nitpick comments (2)
backend/utils/input.validation.js (2)

14-16: Consider adding format validation for username.

The username field only validates length but allows any characters including spaces, special characters, or emojis. Depending on your requirements, you may want to add a regex constraint for alphanumeric characters and common symbols (e.g., underscores, hyphens).

Additionally, consider adding .trim() before validation to prevent whitespace-only or padded usernames from passing validation.

💡 Optional enhancement
     username: z.string()
+        .trim()
         .min(3, { message: "Username must be at least 3 characters." })
-        .max(30, { message: "Username is too long." }),
+        .max(30, { message: "Username is too long." })
+        .regex(/^[a-zA-Z0-9_-]+$/, { message: "Username can only contain letters, numbers, underscores, and hyphens." }),

18-25: Email and password validation is duplicated from loginSchema.

The email and password validation logic is repeated between loginSchema (lines 4-10) and signupSchema. Consider extracting reusable field schemas to reduce duplication and ensure consistency.

♻️ Optional refactor to reduce duplication
// Reusable field schemas
const emailField = z.string()
    .min(1, { message: "Email is required." })
    .email({ message: "Invalid email format." })
    .max(100, { message: "Email is too long." });

const passwordField = z.string()
    .min(6, { message: "Password must be at least 6 characters." })
    .max(100, { message: "Password is too long." });

module.exports.loginSchema = z.object({
    email: emailField,
    password: passwordField
});

module.exports.signupSchema = z.object({
    username: z.string()
        .min(3, { message: "Username must be at least 3 characters." })
        .max(30, { message: "Username is too long." }),
    email: emailField,
    password: passwordField
});

Comment thread backend/controllers/userAuth.controller.js
@yash-pouranik

Copy link
Copy Markdown
Member

@svilupp0 Fix Issues sugggested by Coderabbit

@yash-pouranik
yash-pouranik self-requested a review January 27, 2026 21:04
Comment thread backend/controllers/userAuth.controller.js

@yash-pouranik yash-pouranik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thankx for PR @svilupp0 , feel free to add some big feature or fixing any bug, it will strengthen ur learning. All the best. ❤️

@yash-pouranik
yash-pouranik merged commit 0eead50 into geturbackend:main Jan 28, 2026
4 of 6 checks passed
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.

feat: add username field to signup validation schema

2 participants