public async Task <IResult <IAccessTokenOutput> > Handle(RegisterUserInput userInput, CancellationToken cancellationToken) { var validationResult = Validator.Validate(userInput); if (validationResult.Errors.Count > 0) { return(new Result <IAccessTokenOutput>(validationResult.Errors)); } var user = new User { Email = userInput.UserName, UserName = userInput.UserName, FirstName = userInput.FirstName, LastName = userInput.LastName, SecurityStamp = Guid.NewGuid().ToString() }; var identityResult = await UserService.CreateAsync(user, userInput.Password, cancellationToken); if (!identityResult.Succeeded) { return(new Result <IAccessTokenOutput>(identityResult.Errors)); } var linkUserWithRoleResult = await Mediator.Send(new LinkUserAndRoleInput { UserName = userInput.UserName, RoleName = RoleType.Patient.ToString() }, cancellationToken); if (linkUserWithRoleResult.Errors.Count() > 0) { return(new Result <IAccessTokenOutput>(linkUserWithRoleResult.Errors)); } await PatientRepo.AddAsync(new Patient { IdentityUserId = user.Id, }, cancellationToken); await UoW.SaveAsync(cancellationToken); // Auto login after registrаtion (successful user registration should return access_token) return(await Mediator.Send(new UserCredentialsInput() { UserName = userInput.UserName, Password = userInput.Password }, cancellationToken)); }