feat: implement authenticated user password change functionality, including a new DTO, service method, and API endpoint.

This commit is contained in:
pradeepkumar
2026-02-06 09:45:01 +05:30
parent 750cb55764
commit 895a106d1b
4 changed files with 113 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ import {
ResetPasswordDto,
RefreshTokenDto,
VerifyEmailDto,
ChangePasswordDto,
} from './dto';
import {
VerifyTwoFactorDto,
@@ -201,6 +202,36 @@ export class AuthController {
return this.authService.resetPassword(dto);
}
// ==========================================
// CHANGE PASSWORD
// ==========================================
@Post('change-password')
@UseGuards(JwtAuthGuard)
@HttpCode(HttpStatus.OK)
@ApiBearerAuth('JWT-auth')
@ApiOperation({ summary: 'Change password for authenticated user' })
@ApiBody({ type: ChangePasswordDto })
@ApiResponse({
status: 200,
description: 'Password changed successfully',
schema: {
example: {
success: true,
data: {
message: 'Password changed successfully',
},
},
},
})
@ApiResponse({ status: 400, description: 'Current password is incorrect' })
@ApiResponse({ status: 401, description: 'Unauthorized' })
async changePassword(
@CurrentUser('id') userId: string,
@Body() dto: ChangePasswordDto,
) {
return this.authService.changePassword(userId, dto);
}
// ==========================================
// VERIFY EMAIL
// ==========================================