fix(auth): defer same password check to backend and ensure accurate field error placement (issue #111)

This commit is contained in:
ShivaniKhaire 2026-11-17 15:11:49 +05:30
parent 3240b91f11
commit 7e75204237
1 changed files with 22 additions and 6 deletions

View File

@ -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() {
<FieldLabel label="Current Password" required />
<PasswordInput
value={currentPassword}
onChangeText={setCurrentPassword}
onChangeText={(text) => {
setCurrentPassword(text);
if (currentError) setCurrentError("");
}}
placeholder="Enter current password"
error={currentError}
/>
@ -134,7 +144,10 @@ export default function ChangePasswordScreen() {
<FieldLabel label="New Password" required />
<PasswordInput
value={newPassword}
onChangeText={setNewPassword}
onChangeText={(text) => {
setNewPassword(text);
if (newError) setNewError("");
}}
placeholder="Min. 8 characters with numbers & symbols"
error={newError}
/>
@ -144,7 +157,10 @@ export default function ChangePasswordScreen() {
<FieldLabel label="Confirm New Password" required />
<PasswordInput
value={confirmPassword}
onChangeText={setConfirmPassword}
onChangeText={(text) => {
setConfirmPassword(text);
if (confirmError) setConfirmError("");
}}
placeholder="Re-enter new password"
error={confirmError}
/>