Skip to content

[Bug]: student signup validates current_year but never stores it in the database #277

Description

@anshul23102

Bug Summary

In backend/controllers/auth.controller.js, the student signup path validates current_year (checking that it is between 1 and 6) but never includes it in the User.create call. Every student account created through signup will have current_year as undefined in the database, even though the field exists in studentBioSchema and the client submits a value.

Steps to Reproduce

  1. Send a POST request to the signup endpoint with:
    • userType: 'student'
    • current_year: 3
    • Valid values for all other required fields
  2. The request passes the current_year validation check (1 <= 3 <= 6)
  3. Check the created user document in MongoDB
  4. Observe that student_bio.current_year is undefined (not stored)

Expected Behavior

The validated current_year value (e.g., 3) should be persisted in student_bio.current_year of the newly created user document. Any feature that reads current_year (such as year-based access controls or academic year calculations) should receive the value the student submitted.

Actual Behavior

The User.create call for student signup builds student_bio as follows:

student_bio: {
  gender: req.body.gender || 'male',
  enrollment_year: req.body.enrollment_year || new Date().getFullYear(),
  course: course_id,
  roll_number: req.body.roll_number || null,
  avatar: ''
}

current_year is absent from this object. Despite passing validation, it is silently discarded. The studentBioSchema defines the field with min: 1, max: 6, so the schema already supports it - it is only the controller that omits it.

Environment

  • Backend: Node.js / Express
  • File: backend/controllers/auth.controller.js (student signup branch)
  • Model: backend/models/User.model.js (studentBioSchema.current_year)

Additional Context

The fix is a one-line addition inside User.create:

student_bio: {
  gender: req.body.gender || 'male',
  enrollment_year: req.body.enrollment_year || new Date().getFullYear(),
  current_year: req.body.current_year,   // add this line
  course: course_id,
  roll_number: req.body.roll_number || null,
  avatar: ''
}

Expected NSOC points: Level 2 (medium complexity - validated input silently dropped at the persistence layer)

Suggested labels: bug, NSOC'26, level2

Checklist:

Metadata

Metadata

Assignees

Labels

NSOC'26Issues for the NSOC 2026 program

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions