Repository navigation
fix: return 400 naming the missing field when registering with incomplete input - #224
Merged
TheCodeHeist-Coder merged 1 commit intoOct 27, 2026
Conversation
TheCodeHeist-Coder
approved these changes
Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
POST /api/v1/auth/registerhad no check on the body, so a missing field went straight intoprisma.user.findUnique/bcrypt.hash(undefined, 10), threw, and came back as a generic 500. Now it answers 400 and says which field is the problem.utils/registerInput.ts(parseRegisterInput, a small zod schema, same shape asquestionInput.tsfrom fix: validate question input and keep question order unique #219).userRegisterControllercalls it first, so nothing reachesfindUniqueorbcryptuntilname,emailandpasswordare all real strings. The 400 uses the sameerrorResponseshape as login:{ "success": false, "error": "..." }.password is required,name and password are required,name, email and password are required,password must be a string. Missing,null, empty and whitespace-only all count as "required"; a number, array or object gives "must be a string". A request with no body at all or a JSON array reports all three as required.One thing I found while checking: on main an empty or whitespace-only password was not just a 500 case, it actually registered (201), so you could create an account with password
"". That is rejected now too.Other controllers, as the issue asked me to look (not changed here, to keep this small):
createQuizControlleralready checks!title || !description, but a non-string like{"title": 5}is not caught.joinQuizControllerinsessionController.tschecks presence but answers{ message }instead of{ success, error }, and also does not check types. I can do these as a follow up if you want. I also left email format checking out on purpose, it did not exist for register before and the issue is about missing fields.The terminal output below is the real curl output from the built http-server against a local Postgres, before (upstream main) and after (this branch). I rendered the text into an image with Playwright, and shortened the JWT in the successful responses to its first 12 characters, nothing else is edited.
Before:
After:
Related issue
Closes #191
NSoC 2026, level1.
Type of change
Which services does this touch?
apps/frontendapps/http-serverapps/ws-serverapps/genAIpackages/db(schema or Prisma changes)How did you test this?
Unit tests,
pnpm --filter http-server run test: 70 pass (was 43 on main, 27 new). The new ones areregisterInput.test.ts(the schema and its messages) andauthController.test.ts, which mocks@repo/dbandbcryptand checks that the bad bodies get a 400 and never callfindUnique,bcrypt.hashoruser.create, and that a valid user still gets a 201 and a duplicate email still gets the 400. With the controller change reverted, 5 of the 7 controller tests fail (the two regression ones pass, as they should).Against a real server and database: throwaway PG 18 with
prisma migrate deploy, http-server built withtsc -band started on a local port, same curl cases before and after (in the screenshots):password is requiredemailname and password are required{}or no bodyname, email and password are required"password": ""password is required"password": " "password is required"name": " "name is required"email": nullemail is required"password": 12345678password must be a string"email": {"$ne":"x"}email must be a string"name": ["t"]name must be a string[1,2]name, email and password are requiredEmail is already existed..Email is already existed..pnpm run check-typespasses.pnpm run lintstill exits 1 because of the frontend (20 problems, 18 errors), identical on clean main, nothing from this change.pnpm run buildfails atadmin(VITE_ADMIN_API_URL is not set), also the same on clean main;tsc -bfor http-server on its own builds fine.Not tested: the frontend (not touched),
docker compose up. Side note, not changed here:Signup.tsxreadserror.response?.data?.erorr(typo), so the signup form never shows the server's message and always says "Failed to register...". Happy to fix that in a separate PR.Checklist
pnpm run lint(it runs, but exits non-zero because of 18 errors already on main in the frontend; http-server has none)pnpm run check-typespnpm run build(fails atadminon a missing env var, same on main; http-server builds)docker-compose up.envfile, API key or other secretFirst pull request here? CONTRIBUTING.md walks through the
whole process, and a checkbox left unticked is not a problem — say so and we
will help.