finalizare 1.0
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using Application.Services.Jwt;
|
||||
|
||||
namespace Application.Endpoints.Authorization.RefreshToken;
|
||||
|
||||
public class RefreshJwtHandler(IJwtService jwtService)
|
||||
{
|
||||
public async Task<BaseResponse> Handle(RefreshJwtCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var validator = new RefreshJwtValidator(jwtService);
|
||||
var validationResult = await validator.ValidateAsync(command, cancellationToken);
|
||||
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
var firstError = validationResult.Errors.FirstOrDefault();
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.Unauthorized,
|
||||
Message = firstError?.ErrorMessage
|
||||
};
|
||||
}
|
||||
|
||||
var newToken = jwtService.RefreshToken(command.Token);
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.OK,
|
||||
Message = "Token refreshed successfully.",
|
||||
Data = newToken
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user