Skip to content

refactor: Add schema-level validation for user fields#37

Open
Devexhhh wants to merge 2 commits into
Mayank10123:mainfrom
Devexhhh:improve-user-schema-validation
Open

refactor: Add schema-level validation for user fields#37
Devexhhh wants to merge 2 commits into
Mayank10123:mainfrom
Devexhhh:improve-user-schema-validation

Conversation

@Devexhhh

Copy link
Copy Markdown

Description

This PR adds schema-level validation and sanitization improvements to the User model to improve data integrity, consistency, and backend reliability.

Changes Made

  • Added trim validation for string fields

  • Added lowercase sanitization for email field

  • Added email format validation using regex

  • Added minlength and maxlength constraints where applicable

  • Added numeric validation constraints for:

    • placementProbability
    • streak
    • totalXP
  • Updated password hashing middleware to use modern async middleware pattern compatible with current Mongoose versions

  • Added validation error handling for cleaner API responses

Validation Examples Tested

  • Invalid email formats
  • Short passwords
  • Short names
  • Negative numeric values
  • Successful user creation with valid inputs

Files Modified

  • server/models/User.js

Benefits

  • Prevents malformed or inconsistent data from being stored
  • Improves backend validation reliability
  • Enhances API response correctness
  • Maintains compatibility with existing application functionality

Screenshots

Screenshot 2026-05-24 200704 Screenshot 2026-05-24 200723 Screenshot 2026-05-24 200737 Screenshot 2026-05-24 200747

Closes #34

@vercel

vercel Bot commented May 24, 2026

Copy link
Copy Markdown

@Devexhhh is attempting to deploy a commit to the mayank10123's projects Team on Vercel.

A member of the Team first needs to authorize it.

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 schema-level validation for user fields

1 participant