update password

This commit is contained in:
2026-05-31 20:43:11 +03:30
parent 9afd54b522
commit 7affab06f1
2 changed files with 2 additions and 18 deletions
-10
View File
@@ -203,16 +203,6 @@ export class AuthService {
throw new UnauthorizedException('User not found');
}
if (user.passwordHash) {
if (!dto.currentPassword) {
throw new BadRequestException('Current password is required');
}
const valid = await verifyPassword(dto.currentPassword, user.passwordHash);
if (!valid) {
throw new UnauthorizedException('Current password is incorrect');
}
}
user.passwordHash = await hashPassword(dto.password);
const saved = await this.users.save(user);
return serializeUser(saved);
+2 -8
View File
@@ -1,13 +1,7 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { IsString, MaxLength, MinLength } from 'class-validator';
export class SetPasswordDto {
@ApiPropertyOptional({ description: 'Required when changing an existing password' })
@IsOptional()
@IsString()
@MaxLength(72)
currentPassword?: string;
@ApiProperty({ example: 'mySecurePass123', minLength: 8 })
@IsString()
@MinLength(8)