Enhance user model and authentication controller: add personalRoomId,… - #2
Merged
Conversation
… role, and isVerified fields; improve login and signup responses.
There was a problem hiding this comment.
Pull request overview
This PR extends the backend user/account model to support role-based metadata and a per-user “personal room” identifier, and updates authentication endpoints to return richer, structured user payloads on login/signup/profile.
Changes:
- Add
role,isVerified, andpersonalRoomIdfields to theUserMongoose schema. - Enhance
login,signup, anduserProfileresponses to returnmessageplus a nesteduserobject (including the new fields). - Generate a
personalRoomIdduring signup usingcrypto.randomUUID().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| backend/src/models/User.js | Adds new user attributes (role, isVerified, personalRoomId) to the persisted user schema. |
| backend/src/controllers/auth.controller.js | Normalizes/enhances auth responses and generates/stores personalRoomId during signup. |
Suppressed comments (1)
backend/src/controllers/auth.controller.js:57
fullName/email/passwordare assumed to be strings (password.length,email.toLowerCase()), but only truthiness is checked. Non-string inputs will throw and return 500. Add a type check and normalize the email before validation/querying.
const { fullName, email, password } = req.body;
try {
if (!fullName || !email || !password) {
return res.status(400).json({ message: "All fields are required" });
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+33
to
+37
| personalRoomId: { | ||
| type: String, | ||
| unique: true, | ||
| required: true, | ||
| }, |
Comment on lines
+7
to
+24
| const { email, password } = req.body; | ||
| try { | ||
| if (!email || !password) { | ||
| return res.status(400).json({ message: "Both fields are required" }); | ||
| } | ||
|
|
||
| if (password.length < 6) { | ||
| return res | ||
| .status(400) | ||
| .json({ message: "Password must be at least 6 characters long" }); | ||
| } | ||
|
|
||
| const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
| if (!emailRegex.test(email)) { | ||
| return res.status(400).json({ message: "Invalid email format" }); | ||
| } | ||
|
|
||
| const user = await User.findOne({ email: email.toLowerCase() }); |
Comment on lines
+82
to
+87
| const newUser = new User({ | ||
| fullName, | ||
| email: email.toLowerCase(), | ||
| password: hashedPassword, | ||
| personalRoomId, | ||
| }); |
Comment on lines
+106
to
+109
| } catch (error) { | ||
| console.error("Signup Error:", error); | ||
| res.status(500).json({ message: "Internal Server Error" }); | ||
| } |
Comment on lines
+114
to
+119
| res.clearCookie("jwt", { | ||
| maxAge: 0, | ||
| httpOnly: true, | ||
| secure: process.env.NODE_ENV === "production", | ||
| sameSite: "strict", | ||
| }); |
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.
… role, and isVerified fields; improve login and signup responses.