private async Task <Result <ValidateAuthenticatorDeviceCommandResult, ErrorData> > Process(ValidateAuthenticatorDeviceCommand request, CancellationToken cancellationToken)
        {
            //var whenHappened = this._clock.GetCurrentInstant().ToDateTimeUtc();
            var currentUserMaybe = this._currentUserService.CurrentUser;

            if (currentUserMaybe.HasNoValue)
            {
                return(Result.Fail <ValidateAuthenticatorDeviceCommandResult, ErrorData>(new ErrorData(ErrorCodes.UserNotFound)));
            }

            var userMaybe =
                await this._userRepository.Find(this._currentUserService.CurrentUser.Value.UserId, cancellationToken);

            if (userMaybe.HasNoValue)
            {
                return(Result.Fail <ValidateAuthenticatorDeviceCommandResult, ErrorData>(new ErrorData(ErrorCodes.UserNotFound)));
            }

            var user = userMaybe.Value;
            var authenticatorDevice = user.AuthenticatorDevices.FirstOrDefault(x =>
                                                                               request.AuthenticatorAssertionRawResponse.Id.SequenceEqual(x.CredentialId));

            if (authenticatorDevice == null)
            {
                return(Result.Fail <ValidateAuthenticatorDeviceCommandResult, ErrorData>(new ErrorData(ErrorCodes.DeviceNotFound)));
            }

            var res = await this._fido2.MakeAssertionAsync(request.AuthenticatorAssertionRawResponse, request.AssertionOptions, authenticatorDevice.PublicKey, (uint)authenticatorDevice.Counter, @params => Task.FromResult(true));

            authenticatorDevice.UpdateCounter((int)res.Counter);

            return(Result.Ok <ValidateAuthenticatorDeviceCommandResult, ErrorData>(new ValidateAuthenticatorDeviceCommandResult(res)));
        }
        public async Task <Result <ValidateAuthenticatorDeviceCommandResult, ErrorData> > Handle(ValidateAuthenticatorDeviceCommand request, CancellationToken cancellationToken)
        {
            var result = await this.Process(request, cancellationToken);

            var dbResult = await this._userRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

            if (!dbResult)
            {
                return(Result.Fail <ValidateAuthenticatorDeviceCommandResult, ErrorData>(new ErrorData(
                                                                                             ErrorCodes.SavingChanges, "Failed To Save Database")));
            }

            return(result);
        }