Files
Govor/Govor.API/Controllers/Authentication/RefreshController.cs
T
Artemy 27fdcf85da Use Result.ToActionResult in RefreshController
Import the API extensions and replace manual result handling in RefreshController with result.ToActionResult(), removing the inline empty-token check and switch-based error mapping. Also normalize the empty-token error message in UserSessionRefresher from "cannot be empty" to "can't be empty". This centralizes Result -> IActionResult conversion and simplifies the controller logic.
2026-07-25 20:26:34 +07:00

39 lines
1.1 KiB
C#

using Govor.API.Common.Extensions;
using Govor.Application.Users.UserSessions;
using Govor.Contracts.Requests;
using Govor.Contracts.Responses;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Govor.API.Controllers.Authentication;
[ApiController]
[AllowAnonymous]
[Route("api/auth/token")]
public class RefreshController : Controller
{
private readonly ILogger<RefreshController> _logger;
private readonly IUserSessionRefresher _userSession;
public RefreshController(
ILogger<RefreshController> logger,
IUserSessionRefresher userSession)
{
_logger = logger;
_userSession = userSession;
}
//[RequireHttps]
[HttpPost("refresh")] // api/auth/token/refresh
public async Task<IActionResult> Refresh([FromBody] RefreshTokenRequest refreshRequest)
{
var result = await _userSession.RefreshTokenAsync(refreshRequest.RefreshToken);
if (result.IsFailure)
{
_logger.LogWarning("Refresh token failed. Error Code: {Code}", result.Error.Code);
}
return result.ToActionResult();
}
}