How can I pass validationData in Amplify.Auth.signUp with SWIFT

Viewed 35

I need to register a new user through Cognito. Maybe someone knows how can I send "validationData" in a method on IOS. The following parameters are sent to Cognito on the frontend and it works for them. The new user is being registered:

return {
  username: this.form.value.email,
  password: this.form.value.password,
  attributes: {
    phone_number: this.form.value.phoneNumber,
    given_name: this.form.value.firstName,
    family_name: this.form.value.lastName,
    'custom:country': this.form.value.country.key,
    'custom:pcompl-tac': this.form.value.confirmTermsAndCondition ? CognitoConfirmValue.Confirmed : CognitoConfirmValue.Unconfirmed,
    'custom:emailNotification': this.form.value.confirmEmailSubscription ? CognitoConfirmValue.Confirmed : CognitoConfirmValue.Unconfirmed,
  },
  validationData: {
    recaptchaToken: this.form.value.recaptchaToken,
  },
};

There seems to be no such parameter as "validation data" in the default swift method. I can't figure out how to send "validationData" with Swift for IOS:

func signUp(with model: SignUpModel) {
    print("\(model)")
    let userAttributes = [
        AuthUserAttribute(.phoneNumber, value: model.phoneNumber),
        AuthUserAttribute(.givenName, value: model.firstName),
        AuthUserAttribute(.familyName, value: model.lastName),
        AuthUserAttribute(.custom("country"), value: model.countryKey),
        AuthUserAttribute(.custom("pcompl-tac"), value: model.isTermsAndConditionConfirmedStringValue),
        AuthUserAttribute(.custom("emailNotification"), value: model.isEmailNotificationConfirmedStringValue)
    ]
    
    let options = AuthSignUpRequest.Options(userAttributes: userAttributes)

    Amplify.Auth.signUp(username: model.email, password: model.password, options: options) { result in
        switch result {
        case .success(let signUpResult):
            if case let .confirmUser(deliveryDetails, _) = signUpResult.nextStep {
                print("Delivery details \(String(describing: deliveryDetails))")
            } else {
                print("SignUp Complete")
            }
        case .failure(let error):
            print("An error occurred while registering a user \(error)")
        }
    }
}

Without "validation data" I get the following error in the console: enter image description here

0 Answers
Related