David Cruz
David Cruz

Reputation: 3017

AWS Cognito User Pool - "Value null at 'userName' failed to satisfy constraint: Member must not be null" - iOS

I've been working with UserPools on AWS Mobile Hub. I have managed to log in with providers like Facebook and G+. However, when trying to log in with AWS UserPools, I can't manage to do so. I can Register successfully and connect to the UserPool perfectly (It recognizes wrong passwords and nonexistent users). When I log in with the method shown below, I get the error:

"1 validation error detected: Value null at 'userName' failed to satisfy constraint: Member must not be null."

I don't know what's happening, as the username and password are right! (Even if hardcoded). Here you can see the code I'm using to log in:

    let pool = AWSCognitoIdentityUserPool(forKey: "UserPool")
    let user: AWSCognitoIdentityUser = pool.getUser(textFieldEmail.text!)


    user.getSession(textFieldEmail.text!, password: textFieldPassword.text!, validationData:nil, scopes: nil).continueWithBlock { (task:AWSTask) -> AnyObject? in
           
            if task.error == nil {
                print("Got: \(task.result)")
            } else {
                print("Error while logging in: \(task.error?.userInfo["__type"]) with message: \(task.error?.userInfo["message"])")
            }
            
            return nil
        }

I would really appreciate some help! I've tried to add info on the validation data. Things like:

let userName:AWSCognitoIdentityUserAttributeType = AWSCognitoIdentityUserAttributeType()
    userName.name = "userName"
    iserName.value = textFieldEmail.text

But again, it's not working.

Thanks!

Upvotes: 1

Views: 20379

Answers (2)

Jeff Bailey
Jeff Bailey

Reputation: 5775

That message means the input you're giving for the username is null, I'd dive deeper into how you're populating that field.

As far as validation data goes, don't worry about that. It isn't supposed to go in there, just the username/password fields.

Upvotes: 1

Ionut Trestian
Ionut Trestian

Reputation: 5751

I believe the key should be USERNAME and not userName similar to below:

    let userName:AWSCognitoIdentityUserAttributeType = AWSCognitoIdentityUserAttributeType()
          userName.name = "USERNAME"
          userName.value = textFieldEmail.text

Also, userName.value is misspelled to userName.value You shouldn't be getting this error anymore as we have updated the error messages to reflect the actual keys that should be used (USERNAME in this case).

Upvotes: 0

Related Questions