Skip to content

Commit ef8ea4c

Browse files
Update backend/routes/auth.js
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 17c5dff commit ef8ea4c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

backend/routes/auth.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,19 @@ router.get("/profile", requireAuth, async (req, res) => {
7979
router.put("/profile", requireAuth, async (req, res) => {
8080
try {
8181
const updates = {};
82-
const { username, email, bio, avatar } = req.body;
82+
const { username, email, bio, avatar, newPassword } = req.body;
8383

8484
if (username !== undefined) updates.username = username;
8585
if (email !== undefined) updates.email = email;
8686
if (bio !== undefined) updates.bio = bio;
8787
if (avatar !== undefined) updates.avatar = avatar;
8888

89+
// Handle password update if newPassword is provided
90+
if (newPassword !== undefined && newPassword.trim().length > 0) {
91+
// Password will be hashed by the User model's pre-save hook
92+
updates.password = newPassword;
93+
}
94+
8995
const user = await User.findByIdAndUpdate(req.userId, updates, {
9096
new: true,
9197
runValidators: true,

0 commit comments

Comments
 (0)