chage api use token

This commit is contained in:
JakkrapartXD 2026-01-14 13:42:54 +07:00
parent 6239159099
commit d8a9909eb9
4 changed files with 17 additions and 23 deletions

View file

@ -1,4 +1,4 @@
import { Body, Post, Route, Tags, SuccessResponse, Response, Example, Controller, Security } from 'tsoa';
import { Body, Post, Route, Tags, SuccessResponse, Response, Example, Controller, Security, Request } from 'tsoa';
import { AuthService } from '../services/auth.service';
import {
LoginRequest,
@ -170,7 +170,7 @@ export class AuthController {
if (error) {
throw new ValidationError(error.details[0].message);
}
return await this.authService.resetPassword(body.id, body.token, body.password);
return await this.authService.resetPassword(body.token, body.password);
}
/**
@ -183,11 +183,15 @@ export class AuthController {
@Security('jwt')
@SuccessResponse('200', 'Password changed successfully')
@Response('401', 'Invalid or expired reset token')
public async changePassword(@Body() body: ChangePassword): Promise<{ message: string }> {
public async changePassword(@Request() request: any, @Body() body: ChangePassword): Promise<{ message: string }> {
const { error } = changePasswordSchema.validate(body);
if (error) {
throw new ValidationError(error.details[0].message);
}
return await this.authService.changePassword(body.id, body.oldPassword, body.newPassword);
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) {
throw new ValidationError('No token provided');
}
return await this.authService.changePassword(token, body.oldPassword, body.newPassword);
}
}