【问题标题】:AWS Cognito User Pool - "Value null at 'userName' failed to satisfy constraint: Member must not be null" - iOSAWS Cognito 用户池 - “'userName' 处的值为 null 未能满足约束:成员不得为空” - iOS
【发布时间】:2016-12-27 07:32:17
【问题描述】:

我一直在使用 AWS Mobile Hub 上的 UserPools。我已经设法通过 Facebook 和 G+ 等提供商登录。但是,当尝试使用 AWS UserPools 登录时,我无法这样做。我可以成功注册并完美连接到 UserPool(它识别错误的密码 7 个不存在的用户)。当我使用下面显示的方法登录时,我收到错误:

“检测到 1 个验证错误:'userName' 处的值为 null 未能满足约束:成员不得为 null”

我真的不知道发生了什么,因为用户名和密码实际上是正确的! (即使硬编码)。在这里你可以看到我用来登录的代码:

    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
        }

非常感谢您的帮助!我试图添加有关验证数据的信息。比如:

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

但还是不行。

谢谢!

【问题讨论】:

  • 你找到答案了吗?我目前在这里面临同样的问题。这很令人沮丧。
  • 不! :(@tyegah123
  • 我通过将 SDK 升级到最新版本解决了这个问题。 (2.4.9):D

标签: ios swift amazon-web-services aws-sdk amazon-cognito


【解决方案1】:

该消息意味着您为用户名提供的输入为空,我将深入研究您如何填充该字段。

就验证数据而言,不用担心。它不应该在那里,只是用户名/密码字段。

【讨论】:

  • 我会试试@Jeff!非常感谢
【解决方案2】:

我认为密钥应该是 USERNAME 而不是类似于下面的 userName:

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

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

【讨论】:

    猜你喜欢
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    • 2021-12-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多