fix(auth): normalize email storage and lookup handling#327
fix(auth): normalize email storage and lookup handling#327VarshithReddy2006 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughEmail normalization (lowercase + trim) is applied consistently at write time across all three user creation flows in ChangesEmail Normalization at Write Paths
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@apps/public-api/src/controllers/userAuth.controller.js`:
- Around line 1343-1346: The response format in the user creation endpoint does
not conform to the required API response envelope. The current response returns
an object with message and user properties, but it must return an object with
success (boolean), data (containing the user information), and message
properties. Restructure the res.status(201).json() call to wrap the user object
in a data property and add a success property set to true, while keeping the
message property.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4cc090bc-cf98-4b09-9796-64c76f2f6d36
📒 Files selected for processing (1)
apps/public-api/src/controllers/userAuth.controller.js
| res.status(201).json({ | ||
| message: "User created successfully", | ||
| user: { _id: result._id, email, username, createdAt: newUserPayload.createdAt } | ||
| user: { _id: result._id, email: normalizedEmail, username, createdAt: newUserPayload.createdAt } | ||
| }); |
There was a problem hiding this comment.
Return the required controller response envelope
This endpoint still returns { message, user } instead of the required { success, data, message } contract.
As per coding guidelines, “All API endpoints must return response format: { success: bool, data: {}, message: "" }.”
Proposed fix
- res.status(201).json({
- message: "User created successfully",
- user: { _id: result._id, email: normalizedEmail, username, createdAt: newUserPayload.createdAt }
- });
+ res.status(201).json({
+ success: true,
+ data: {
+ user: { _id: result._id, email: normalizedEmail, username, createdAt: newUserPayload.createdAt }
+ },
+ message: "User created successfully"
+ });🤖 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 `@apps/public-api/src/controllers/userAuth.controller.js` around lines 1343 -
1346, The response format in the user creation endpoint does not conform to the
required API response envelope. The current response returns an object with
message and user properties, but it must return an object with success
(boolean), data (containing the user information), and message properties.
Restructure the res.status(201).json() call to wrap the user object in a data
property and add a success property set to true, while keeping the message
property.
Source: Coding guidelines
|
@VarshithReddy2006 fix the issue reported by coderabbit |
|
I reviewed the CodeRabbit comment. This PR is scoped specifically to Issue #321 (email normalization). The I intentionally kept the PR limited to normalizing email storage and lookup behavior to avoid introducing unrelated API-contract changes in the same bug fix. If you'd prefer the response envelope to be standardized for Thank you. |
Fixes #321
Summary
This PR normalises email addresses before both storage and lookup across authentication flows.
Changes
Problem
Authentication flows performed normalised email lookups, while some user creation paths stored raw email values. This could lead to inconsistencies for mixed-case email addresses and make authentication behaviour dependent on how the email was originally stored.
Result
Email storage and lookup now use the same canonical representation (
toLowerCase().trim()) across the affected authentication flows, ensuring consistent behaviour and reliable email matching.Summary by CodeRabbit