2016-08-20 63 views
1

我一直在使用AWS Mobile Hub上的UserPools。我設法使用Facebook和G +等提供商進行登錄。但是,嘗試使用AWS UserPools登錄時,我無法做到這一點。我可以成功註冊並完美連接到UserPool(它識別錯誤的密碼7不存在的用戶)。當我用下面所示的方法登錄,我得到的錯誤:AWS Cognito用戶池 - 「在'用戶名'的空值不能滿足約束:成員不能爲空」 - iOS

"1 validation error detected: Value null at 'userName' failed to satisfy constraint: Member must not be 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 

但是,再次,不工作。

謝謝!

+0

您是否找到了答案?我目前在這裏面臨同樣的問題。這很令人沮喪。 – tyegah123

+0

不! :(@ tyegah123 –

+1

我通過將SDK升級到最新版本解決了這個問題。(2.4.9):D – tyegah123

回答

-1

我認爲關鍵要USERNAME,而不是用戶名類似如下:

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

此外,userName.value拼錯到userName.value你不應該再得到這個錯誤,因爲我們已經更新了錯誤消息來反映應該使用的實際密鑰(本例中爲USERNAME)。

0

該消息表示您爲用戶名輸入的輸入爲空,我會深入探討如何填充該字段。

就驗證數據而言,不要擔心這一點。它不應該在那裏,只是用戶名/密碼字段。

+0

我會試試@Jeff!非常感謝 –

相關問題