简体   繁体   English

AWS Cognito 用户池 - “'userName' 处的值为 null 未能满足约束:成员不得为 null” - iOS

[英]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.我一直在使用 AWS Mobile Hub 上的 UserPools。 I have managed to make login with providers like Facebook and G+.我已经设法通过 Facebook 和 G+ 等提供商登录。 However, when trying to login with AWS UserPools I can't manage to do so.但是,在尝试使用 AWS UserPools 登录时,我无法这样做。 I can Register successfully and connect to the UserPool perfectly (It recognizes wrong passwords 7 nonexistent users).我可以成功注册并完美连接到用户池(它识别错误密码 7 个不存在的用户)。 When I login 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" “检测到 1 个验证错误:‘userName’处的空值未能满足约束:成员不得为空”

I don't really know whats happening as the username and password are actually right!我真的不知道发生了什么,因为用户名和密码实际上是正确的! (Even if hardcoded). (即使硬编码)。 Here you can see the code I'm using to login:在这里你可以看到我用来登录的代码:

    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, not working.但同样,不工作。

Thanks!谢谢!

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.它不应该进入那里,只是用户名/密码字段。

I believe the key should be USERNAME and not userName similar to below:我相信密钥应该是 USERNAME 而不是类似于下面的 userName:

    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).此外,userName.value 拼错为 userName.value 您不应再收到此错误,因为我们已更新错误消息以反映应使用的实际键(在本例中为 USERNAME)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM