From 9a28552af54bbc0d8401d9403c16657dfde99f26 Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Sun, 19 Nov 2023 08:56:03 -0500 Subject: [PATCH] bug fix --- .../users/userId/deleteUserById.ts | 22 +++++++++------- pages/settings/delete.tsx | 26 ++++++++++--------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/lib/api/controllers/users/userId/deleteUserById.ts b/lib/api/controllers/users/userId/deleteUserById.ts index 91c507c..c32b1fb 100644 --- a/lib/api/controllers/users/userId/deleteUserById.ts +++ b/lib/api/controllers/users/userId/deleteUserById.ts @@ -21,17 +21,19 @@ export default async function deleteUserById( }; } - // Then, we check if the provided password matches the one stored in the database - const isPasswordValid = bcrypt.compareSync( - body.password, - user.password || "" - ); + // Then, we check if the provided password matches the one stored in the database (disabled in Keycloak integration) + if (!process.env.KEYCLOAK_CLIENT_SECRET) { + const isPasswordValid = bcrypt.compareSync( + body.password, + user.password as string + ); - if (!isPasswordValid) { - return { - response: "Invalid credentials.", - status: 401, // Unauthorized - }; + if (!isPasswordValid) { + return { + response: "Invalid credentials.", + status: 401, // Unauthorized + }; + } } // Delete the user and all related data within a transaction diff --git a/pages/settings/delete.tsx b/pages/settings/delete.tsx index a901400..3718c61 100644 --- a/pages/settings/delete.tsx +++ b/pages/settings/delete.tsx @@ -25,7 +25,7 @@ export default function Password() { }, }; - if (password == "") { + if (process.env.NEXT_PUBLIC_KEYCLOAK_ENABLED !== "true" && password == "") { return toast.error("Please fill the required fields."); } @@ -78,18 +78,20 @@ export default function Password() { . This action is irreversible!

-
-

- Confirm Your Password -

+ {process.env.NEXT_PUBLIC_KEYCLOAK_ENABLED !== "true" ? ( +
+

+ Confirm Your Password +

- setPassword(e.target.value)} - placeholder="••••••••••••••" - type="password" - /> -
+ setPassword(e.target.value)} + placeholder="••••••••••••••" + type="password" + /> +
+ ) : undefined} {process.env.NEXT_PUBLIC_STRIPE ? (