fix(auth): defer same password check to backend and ensure accurate field error placement (issue #111)
This commit is contained in:
parent
3240b91f11
commit
7e75204237
|
|
@ -42,9 +42,6 @@ export default function ChangePasswordScreen() {
|
||||||
if (!newPassword) {
|
if (!newPassword) {
|
||||||
setNewError("New password is required");
|
setNewError("New password is required");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (currentPassword && newPassword === currentPassword) {
|
|
||||||
setNewError("New password cannot be the same as current password");
|
|
||||||
hasError = true;
|
|
||||||
} else if (newPassword.length < 8) {
|
} else if (newPassword.length < 8) {
|
||||||
setNewError("New password must be at least 8 characters");
|
setNewError("New password must be at least 8 characters");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
|
|
@ -97,6 +94,16 @@ export default function ChangePasswordScreen() {
|
||||||
errMsg.toLowerCase().includes("same")
|
errMsg.toLowerCase().includes("same")
|
||||||
) {
|
) {
|
||||||
setNewError(errMsg);
|
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 {
|
} else {
|
||||||
setCurrentError(errMsg);
|
setCurrentError(errMsg);
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +131,10 @@ export default function ChangePasswordScreen() {
|
||||||
<FieldLabel label="Current Password" required />
|
<FieldLabel label="Current Password" required />
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
value={currentPassword}
|
value={currentPassword}
|
||||||
onChangeText={setCurrentPassword}
|
onChangeText={(text) => {
|
||||||
|
setCurrentPassword(text);
|
||||||
|
if (currentError) setCurrentError("");
|
||||||
|
}}
|
||||||
placeholder="Enter current password"
|
placeholder="Enter current password"
|
||||||
error={currentError}
|
error={currentError}
|
||||||
/>
|
/>
|
||||||
|
|
@ -134,7 +144,10 @@ export default function ChangePasswordScreen() {
|
||||||
<FieldLabel label="New Password" required />
|
<FieldLabel label="New Password" required />
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
value={newPassword}
|
value={newPassword}
|
||||||
onChangeText={setNewPassword}
|
onChangeText={(text) => {
|
||||||
|
setNewPassword(text);
|
||||||
|
if (newError) setNewError("");
|
||||||
|
}}
|
||||||
placeholder="Min. 8 characters with numbers & symbols"
|
placeholder="Min. 8 characters with numbers & symbols"
|
||||||
error={newError}
|
error={newError}
|
||||||
/>
|
/>
|
||||||
|
|
@ -144,7 +157,10 @@ export default function ChangePasswordScreen() {
|
||||||
<FieldLabel label="Confirm New Password" required />
|
<FieldLabel label="Confirm New Password" required />
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
value={confirmPassword}
|
value={confirmPassword}
|
||||||
onChangeText={setConfirmPassword}
|
onChangeText={(text) => {
|
||||||
|
setConfirmPassword(text);
|
||||||
|
if (confirmError) setConfirmError("");
|
||||||
|
}}
|
||||||
placeholder="Re-enter new password"
|
placeholder="Re-enter new password"
|
||||||
error={confirmError}
|
error={confirmError}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue