Skip to content

High performance self-hosted photo and video management solution.

chore: reset shouldChangePassword on password change (#31276)

shenlongdb6a5b0d567f
diff --git a/server/src/services/auth.service.spec.ts b/server/src/services/auth.service.spec.ts
index ed8f1c1b30..be2d7fd3c0 100644
--- a/server/src/services/auth.service.spec.ts
+++ b/server/src/services/auth.service.spec.ts
@@ -110,6 +110,22 @@ describe(AuthService.name, () => {
});
});
+ it('should clear shouldChangePassword', async () => {
+ const user = UserFactory.create();
+ const auth = AuthFactory.create(user);
+ const dto = { password: 'old-password', newPassword: 'new-password' };
+
+ mocks.user.getForChangePassword.mockResolvedValue({ id: user.id, password: 'hash-password' });
+ mocks.user.update.mockResolvedValue(user);
+
+ await sut.changePassword(auth, dto);
+
+ expect(mocks.user.update).toHaveBeenCalledWith(user.id, {
+ password: 'new-password (hashed)',
+ shouldChangePassword: false,
+ });
+ });
+
it('should throw when password does not match existing password', async () => {
const user = UserFactory.create();
const auth = AuthFactory.create(user);
diff --git a/server/src/services/auth.service.ts b/server/src/services/auth.service.ts
index 1259b0f359..f257bc1159 100644
--- a/server/src/services/auth.service.ts
+++ b/server/src/services/auth.service.ts
@@ -135,7 +135,10 @@ export class AuthService extends BaseService {
const hashedPassword = await this.cryptoRepository.hashBcrypt(newPassword, SALT_ROUNDS);
- const updatedUser = await this.userRepository.update(user.id, { password: hashedPassword });
+ const updatedUser = await this.userRepository.update(user.id, {
+ password: hashedPassword,
+ shouldChangePassword: false,
+ });
await this.eventRepository.emit('AuthChangePassword', {
userId: user.id,