mirror of
https://github.com/Govor-team/Govor.git
synced 2026-09-17 16:22:49 +00:00
27fdcf85da
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.
39 lines
1.1 KiB
C#
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();
|
|
}
|
|
} |