public async Task <IActionResult> Login([FromBody] CreateUser createUser) { IActionResult response = Unauthorized(); var user = await _userService.Login(createUser.Email, createUser.Password); if (user != null) { var tokenString = await _jwtHandler.GenerateToken(user); response = Ok(new { token = tokenString }); } return(response); }
public async Task <JsonWebToken> SigninUser(UserAuthDto model) { var queryResult = await Collection.FindAsync(x => x.Username == model.Username); var userDetails = queryResult.FirstOrDefault(); if (userDetails is null) { return(null); } var isValidPassword = BCrypt.Net.BCrypt.Verify(model.Password, userDetails.Password); if (!isValidPassword) { return(null); } return(_jwtHandler.GenerateToken(userDetails.Id.ToString(), null)); }