Created
May 1, 2020 17:54
-
-
Save cardoso/0403c2e01cec6e9c2a4a2b9da70a0020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension AuthViewController: ASAuthorizationControllerDelegate { | |
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { | |
let cred = authorization.credential as! ASAuthorizationAppleIDCredential | |
let code = String(data: cred.authorizationCode!, encoding: .utf8)! | |
var name: String? = nil | |
if let fullName = cred.fullName { | |
name = PersonNameComponentsFormatter().string(from: fullName) | |
} | |
let request = AuthRequest(appleUid: cred.user, appleAuthCode: code, name: name) | |
authenticate(request: request) { [weak self] res, error in | |
DispatchQueue.main.async { | |
guard let res = res else { | |
let alert = UIAlertController(title: "Error", message: error, preferredStyle: .alert) | |
alert.addAction(UIAlertAction(title: "OK", style: .default)) | |
self?.present(alert, animated: true) | |
return | |
} | |
Client.config = .init(apiKey: res.apiKey, logOptions: .info) | |
let extraData = UserExtraData(name: res.name) | |
let user = User(id: res.streamId, extraData: extraData) | |
Client.shared.set(user: user, token: res.streamToken) | |
self?.performSegue(withIdentifier: "kAuthToContactsSegueId", sender: nil) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment