From 4e91b2f1fb5258f87b3a89bed6a3cc5c583e02a4 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Sun, 8 Sep 2024 10:08:24 +0100 Subject: [PATCH] ENCOA-202: Fixed issue updating user --- src/pages/api/users/update.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/api/users/update.ts b/src/pages/api/users/update.ts index 4f7ba431..121a01b3 100644 --- a/src/pages/api/users/update.ts +++ b/src/pages/api/users/update.ts @@ -77,7 +77,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { const queryId = req.query.id as string; - let user = await db.collection("users").findOne({ id: queryId ? (queryId as string) : req.session.user.id }); + const userId = queryId ? (queryId as string) : req.session.user.id + let user = await db.collection("users").findOne({ id: userId }); const updatedUser = req.body as User & { password?: string; newPassword?: string }; if (!!queryId) { @@ -160,7 +161,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { delete updatedUser.newPassword; await db.collection("users").updateOne( - { id: queryId }, + { id: userId }, { $set: updatedUser } );