AWS Cognito getSession

Viewed 1373

I am trying log users as simply as possible using the signup and getSession function. I have not encountered difficulties in using the signup function to create new users in my cognate user pool. When I try to create a function for logging, I try this code :

func signin(){
    let pool = AWSCognitoIdentityUserPool(forKey: AWSCognitoUserPoolSignInProviderKey)

    let user = pool.getUser("toto")

     user.getSession("toto", password: "BabaBobo1&", validationData: nil).continueWith(block: {[weak self] (task) -> Any? in

        DispatchQueue.main.async {
            if let error = task.error as? NSError {
                let alertController = UIAlertController(title: error.userInfo["__type"] as? String,
                                                        message: error.userInfo["message"] as? String,
                                                        preferredStyle: .alert)
                let retryAction = UIAlertAction(title: "Retry", style: .default, handler: nil)
                alertController.addAction(retryAction)
                self?.present(alertController, animated: true, completion: nil)
            }else if let session = task.result {
                let alertController = UIAlertController(title: "token",
                                                        message: session.accessToken?.tokenString,
                                                        preferredStyle: .alert)
                let OKAction = UIAlertAction(title: "OK", style: .default, handler: nil)
                alertController.addAction(OKAction)
                self?.present(alertController, animated: true, completion: nil)

            }
        }

        return nil
    })
}

It appears that the trailing block is never executed. Does anyone knows what I am doing wrong ? My aim is to reduce the AWS linked code to the minimum. I want to avoid as much as possible to use the different delegate protocols provided in the SDK

0 Answers
Related