public async Task <AuthResponse> SignIn(AuthRequest authRequest) { try { var user = await _usersDataManagerTsHelpers.GetUserByUsernameAndPassword(authRequest.Username, authRequest.Password); if (user == null) { throw new OutputException( new Exception(INVALID_USERNAME_OR_PASSWORD), StatusCodes.Status401Unauthorized, MnemoxStatusCodes.INVALID_USERNAME_OR_PASSWORD); } var token = _secretsManager.GenerateToken(); var tokenValidUntilUtc = DateTime.UtcNow.AddMinutes(TOKEN_VALID_MINUTES); var tokenId = await _usersDataManagerTsHelpers.SetSignedInUserIntoStorage(user, token, tokenValidUntilUtc); return(new AuthResponse { Token = token }); } catch (OutputException) { throw; } catch (HandledException) { throw; } catch (Exception ex) { await _logsManager.ErrorAsync(new ErrorLogStructure(ex).WithErrorSource()); throw new HandledException(ex); } }