diff options
author | HombreLaser <sebastian-440@live.com> | 2022-11-16 21:46:27 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2022-11-16 21:46:27 -0600 |
commit | d9811fb5fca308d4cd3eb0039627c1182472069a (patch) | |
tree | b18c7f5cc72370f38d7e33bba06557e96ebd1743 /Controllers | |
parent | 7885b71dad3a2dea21b64532f6a825ce033bf0a6 (diff) |
Añadido manejo de errores en signup
Diffstat (limited to 'Controllers')
-rw-r--r-- | Controllers/UsersController.cs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Controllers/UsersController.cs b/Controllers/UsersController.cs index 5483a6b..9e66fce 100644 --- a/Controllers/UsersController.cs +++ b/Controllers/UsersController.cs @@ -26,11 +26,13 @@ namespace IdentityAPI.Controllers { [HttpPost("signup")] public async Task<IActionResult> SignUp(UserDTO data) { - var user = new IdentityUser { UserName = data.UserName, Email = data.Email }; - var result = await _manager.CreateAsync(user, data.Password); + if(data.Email != null && data.Password != null) { + var user = new IdentityUser { UserName = data.UserName, Email = data.Email }; + var result = await _manager.CreateAsync(user, data.Password); - if(result.Succeeded) - return Ok(new { Token = GenerateToken(user) }); + if(result.Succeeded) + return Ok(new { Token = GenerateToken(user) }); + } return StatusCode(422, new { error = "The provided user is invalid" }); } |