Skip to content

Commit

Permalink
fix(server) Cannot change first time password due to null in first an…
Browse files Browse the repository at this point in the history
…d last name payload (#1205)

* fix(server) Cannot change first time password due to null in first and last name payload

* Added error message for form on the web
  • Loading branch information
alextran1502 authored Dec 29, 2022
1 parent 7810dd1 commit 1eb9ac8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
16 changes: 15 additions & 1 deletion server/apps/immich/src/api-v1/user/user.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,25 @@ export class UserCore {
}
}

const user = await this.userRepository.get(id);
if (!user) {
throw new NotFoundException('User not found');
}

try {
if (dto.password) {
dto.password = await hash(dto.password, SALT_ROUNDS);
}
return this.userRepository.update(id, dto);

user.password = dto.password ?? user.password;
user.email = dto.email ?? user.email;
user.firstName = dto.firstName ?? user.firstName;
user.lastName = dto.lastName ?? user.lastName;
user.isAdmin = dto.isAdmin ?? user.isAdmin;
user.shouldChangePassword = dto.shouldChangePassword ?? user.shouldChangePassword;
user.profileImagePath = dto.profileImagePath ?? user.profileImagePath;

return this.userRepository.update(id, user);
} catch (e) {
Logger.error(e, 'Failed to update user info');
throw new InternalServerErrorException('Failed to update user info');
Expand Down
46 changes: 31 additions & 15 deletions web/src/lib/components/forms/create-user-form.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<script lang="ts">
import { api } from '@api';
import { createEventDispatcher } from 'svelte';
import {
notificationController,
NotificationType
} from '../shared-components/notification/notification';
let error: string;
let success: string;
Expand Down Expand Up @@ -38,23 +42,35 @@
const firstName = form.get('firstName');
const lastName = form.get('lastName');
const { status } = await api.userApi.createUser({
email: String(email),
password: String(password),
firstName: String(firstName),
lastName: String(lastName)
});
if (status === 201) {
success = 'New user created';
dispatch('user-created');
isCreatingUser = false;
return;
} else {
try {
const { status } = await api.userApi.createUser({
email: String(email),
password: String(password),
firstName: String(firstName),
lastName: String(lastName)
});
if (status === 201) {
success = 'New user created';
dispatch('user-created');
isCreatingUser = false;
return;
} else {
error = 'Error create user account';
isCreatingUser = false;
}
} catch (e) {
error = 'Error create user account';
isCreatingUser = false;
console.log('[ERROR] registerUser', e);
notificationController.show({
message: `Error create new user, check console for more detail`,
type: NotificationType.Error
});
}
}
}
Expand Down

1 comment on commit 1eb9ac8

@vercel
Copy link

@vercel vercel bot commented on 1eb9ac8 Dec 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.