Skip to content

Commit

Permalink
Make user password set consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Jun 11, 2024
1 parent aa99978 commit 9f89942
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions web/src/components/users/FirstUserForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ export default function FirstUserForm() {
return user;
}, user);

if (!changePassword) {
delete user.password;
delete user.passwordConfirmation;
}

// Preserve current password value if the user was not editing it.
if (state.isEditing && user.password === "") delete user.password;
delete user.passwordConfirmation;
Expand All @@ -147,6 +152,11 @@ export default function FirstUserForm() {
return;
}

if (state.isEditing && changePassword && !user.password) {
setErrors([_("Password is required")]);
return;
}

const { result, issues = [] } = await client.users.setUser({ ...state.user, ...user });
if (!result || issues.length) {
// FIXME: improve error handling. See client.
Expand Down

0 comments on commit 9f89942

Please sign in to comment.