AWS Cognito getSession

I am trying to use log users as simple as possible using the signup and getSession functions. I had no difficulty using the registration function to create new users in my own 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 seems that the trailing block is never executed. Does anyone know what I'm doing wrong? My goal is to keep AWS code to a minimum. I want to avoid using the different delegate protocols presented in the SDK as much as possible

+4
source share

Source: https://habr.com/ru/post/1681104/


All Articles