using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; /// /// JWT authentication: login and current-user profile. /// [ApiController] [Route("api/v1/auth")] [Produces("application/json")] public class AuthController : ControllerBase { private readonly IAuthService _auth; public AuthController(IAuthService auth) => _auth = auth; /// Authenticate and receive a JWT bearer token. [HttpPost("login")] [AllowAnonymous] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status422UnprocessableEntity)] public async Task Login([FromBody] LoginRequest req) { var result = await _auth.LoginAsync(req); return Ok(ApiResponse.Ok(result)); } /// Returns the authenticated user's profile. [HttpGet("me")] [Authorize] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] public IActionResult Me([FromServices] ICurrentUserService currentUser) { return Ok(ApiResponse.Ok(new { userId = currentUser.UserId, username = currentUser.Username, displayName = currentUser.DisplayName, role = currentUser.Role?.ToDbString() })); } }