I've been working on an iOS application that uses AWS Mobile Hub as a backend, and I can't seem to figure out how to implement a custom authentication UI for the User sign in feature. Better yet, I can't find any docs that at least give a hint at how i'm supposed to do it. The only single bit of resources I found was AWS's provided Auth UI feature, which is not ideal in my circumstance. (i should mention that I am a bit new to AWS development on swift)
The idea is I can use the provided awsconfiguration.json
given to you when you launch a new project on Mobile Hub, then integrate it into a UIViewController class to use for authentication without using the AuthUI library.
Here's what i've tried:
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passwordField: UITextField!
var passwordAuthenticationCompletion: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>!
func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>) {
passwordAuthenticationCompletion = passwordAuthenticationCompletionSource
}
@IBAction func logInTapped(_ sender: Any) {
var emailText = emailField.text!
var passwordText = passwordField.text!
passwordAuthenticationCompletion.set(result: AWSCognitoIdentityPasswordAuthenticationDetails.init(username: emailText, password: passwordText))
}
func didCompleteStepWithError(_ error: Error?) {
if error != nil {
let alertController = UIAlertController(title: error?.localizedDescription, message: "error", preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default, handler: nil))
self.present(alertController, animated: true, completion: nil)
} else {
print("logged in")
}
}
I get returned nil when passwordAuthenticationCompletion.set()
is called.
Could somebody tell me what i'm doing wrong, or possibly point me in the right direction?
Thanks.