Ejemplo n.º 1
0
        public async Task <IActionResult> SignIn([FromBody] SignIn request)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            var command = new AuthorizeUser
            {
                Username = request.Username,
                Password = request.Password
            };

            var result = await _userService.AuthorizeUserAsync(command);

            if (result.Failure)
            {
                return(StatusCode(403, new ApiError {
                    ErrorCode = result.Error.Code, Message = result.Error.Message
                }));
            }

            var token = _jwtHandler.Create(result.Result.Id, request.Username);

            return(Ok(token));
        }