From 7e75204237322cdcdcff8b1b7180e637b8b9a0d4 Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Tue, 17 Nov 2026 15:11:49 +0530 Subject: [PATCH] fix(auth): defer same password check to backend and ensure accurate field error placement (issue #111) --- src/app/profile/change-password.tsx | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/app/profile/change-password.tsx b/src/app/profile/change-password.tsx index c59d46d..301112a 100644 --- a/src/app/profile/change-password.tsx +++ b/src/app/profile/change-password.tsx @@ -42,9 +42,6 @@ export default function ChangePasswordScreen() { if (!newPassword) { setNewError("New password is required"); hasError = true; - } else if (currentPassword && newPassword === currentPassword) { - setNewError("New password cannot be the same as current password"); - hasError = true; } else if (newPassword.length < 8) { setNewError("New password must be at least 8 characters"); hasError = true; @@ -97,6 +94,16 @@ export default function ChangePasswordScreen() { errMsg.toLowerCase().includes("same") ) { setNewError(errMsg); + } else if ( + typeof errMsg === "string" && + (errMsg.toLowerCase().includes("current") || errMsg.toLowerCase().includes("old")) + ) { + setCurrentError(errMsg); + } else if ( + typeof errMsg === "string" && + errMsg.toLowerCase().includes("confirm") + ) { + setConfirmError(errMsg); } else { setCurrentError(errMsg); } @@ -124,7 +131,10 @@ export default function ChangePasswordScreen() { { + setCurrentPassword(text); + if (currentError) setCurrentError(""); + }} placeholder="Enter current password" error={currentError} /> @@ -134,7 +144,10 @@ export default function ChangePasswordScreen() { { + setNewPassword(text); + if (newError) setNewError(""); + }} placeholder="Min. 8 characters with numbers & symbols" error={newError} /> @@ -144,7 +157,10 @@ export default function ChangePasswordScreen() { { + setConfirmPassword(text); + if (confirmError) setConfirmError(""); + }} placeholder="Re-enter new password" error={confirmError} />