docs: update configuration and documentation for token validation

This commit is contained in:
Aaron Po
2026-02-28 23:19:12 -05:00
parent c20be03f89
commit c5571fcf47
5 changed files with 292 additions and 26 deletions

View File

@@ -0,0 +1,19 @@
using FluentValidation;
namespace API.Core.Contracts.Auth;
public record RefreshTokenRequest
{
public string RefreshToken { get; init; } = default!;
}
public class RefreshTokenRequestValidator
: AbstractValidator<RefreshTokenRequest>
{
public RefreshTokenRequestValidator()
{
RuleFor(x => x.RefreshToken)
.NotEmpty()
.WithMessage("Refresh token is required");
}
}

View File

@@ -11,7 +11,8 @@ namespace API.Core.Controllers
public class AuthController(
IRegisterService registerService,
ILoginService loginService,
IConfirmationService confirmationService
IConfirmationService confirmationService,
ITokenService tokenService
) : ControllerBase
{
[HttpPost("register")]
@@ -80,5 +81,28 @@ namespace API.Core.Controllers
}
);
}
[HttpPost("refresh")]
public async Task<ActionResult> Refresh(
[FromBody] RefreshTokenRequest req
)
{
var rtn = await tokenService.RefreshTokenAsync(
req.RefreshToken
);
return Ok(
new ResponseBody<LoginPayload>
{
Message = "Token refreshed successfully.",
Payload = new LoginPayload(
rtn.UserAccount.UserAccountId,
rtn.UserAccount.Username,
rtn.RefreshToken,
rtn.AccessToken
),
}
);
}
}
}