Guest User

Untitled

a guest
Dec 12th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. func signIn(createdUsernameValue: String, passwordValue: String){
  2. // Signin the user
  3. let authDetails = AWSCognitoIdentityPasswordAuthenticationDetails(username: createdUsernameValue, password: passwordValue)
  4. self?.passwordAuthenticationCompletion?.set(result: authDetails)
  5. self?.user = self?.pool?.currentUser()
  6.  
  7. print("self.user :\(self?.user)" )
  8.  
  9. self?.pool?.currentUser()?.getSession(userNameValue, password: passwordValue, validationData: nil).continueOnSuccessWith(executor: AWSExecutor.mainThread(), block: { (task) -> Any? in
  10. if(task.error == nil){
  11. print("user is logged in")
  12. getUserId()
  13. let myTask = task.result
  14.  
  15. } else{
  16. print("There is an error in the signin process")
  17. }
  18. return nil
  19. })
  20. }
  21.  
  22.  
  23. func getUserId(){
  24. print("Get userId func called")
  25. self.pool?.currentUser()?.getDetails().continueWith(block: { (task) -> Any? in
  26. if(task.error == nil){
  27. print("user is logged in")
  28. self.response = task.result
  29. if let response = self.response {
  30. let attributes = response.userAttributes
  31.  
  32. guard let userId = attributes![0].value as? String else { return nil}
  33. guard let phoneNumberVerified = attributes![1].value as? String else { return nil }
  34. guard let phoneNumber = attributes![2].value as? String else { return nil }
  35.  
  36. print("userId: \(userId)")
  37.  
  38. }
  39.  
  40. } else{
  41. print("There is an error in the signin process")
  42. print("Error: \(task.error)")
  43. }
  44.  
  45. return nil
  46. }, cancellationToken: nil)
  47. }
Add Comment
Please, Sign In to add comment